refactor(virus_scan): remove lock
This commit is contained in:
parent
6e18090fb3
commit
c4a30084fe
5 changed files with 3 additions and 25 deletions
|
@ -10,7 +10,7 @@ class Champs::PieceJustificativeController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if attach_piece_justificative_or_retry
|
if attach_piece_justificative
|
||||||
render :show
|
render :show
|
||||||
else
|
else
|
||||||
render json: { errors: @champ.errors.full_messages }, status: 422
|
render json: { errors: @champ.errors.full_messages }, status: 422
|
||||||
|
@ -46,10 +46,4 @@ class Champs::PieceJustificativeController < ApplicationController
|
||||||
|
|
||||||
save_succeed
|
save_succeed
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach_piece_justificative_or_retry
|
|
||||||
attach_piece_justificative
|
|
||||||
rescue ActiveRecord::StaleObjectError
|
|
||||||
attach_piece_justificative
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,7 @@ module ActiveJob::RetryOnTransientErrors
|
||||||
Excon::Error::InternalServerError,
|
Excon::Error::InternalServerError,
|
||||||
Excon::Error::GatewayTimeout,
|
Excon::Error::GatewayTimeout,
|
||||||
Excon::Error::BadRequest,
|
Excon::Error::BadRequest,
|
||||||
Excon::Error::Socket,
|
Excon::Error::Socket
|
||||||
ActiveRecord::StaleObjectError
|
|
||||||
]
|
]
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
|
|
@ -2,6 +2,7 @@ module BlobVirusScannerConcern
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
self.ignored_columns = [:lock_version]
|
||||||
before_create :set_pending
|
before_create :set_pending
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,10 @@ class CommentaireService
|
||||||
|
|
||||||
def self.save(dossier, params)
|
def self.save(dossier, params)
|
||||||
build_and_save(dossier, params)
|
build_and_save(dossier, params)
|
||||||
rescue ActiveRecord::StaleObjectError
|
|
||||||
build_and_save(dossier, params)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.save!(dossier, params)
|
def self.save!(dossier, params)
|
||||||
build_and_save(dossier, params, raise_exception: true)
|
build_and_save(dossier, params, raise_exception: true)
|
||||||
rescue ActiveRecord::StaleObjectError
|
|
||||||
build_and_save(dossier, params, raise_exception: true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_and_save(dossier, params, raise_exception: false)
|
def self.build_and_save(dossier, params, raise_exception: false)
|
||||||
|
|
|
@ -15,18 +15,6 @@ describe VirusScannerJob, type: :job do
|
||||||
end
|
end
|
||||||
it { expect(blob.virus_scanner.safe?).to be_truthy }
|
it { expect(blob.virus_scanner.safe?).to be_truthy }
|
||||||
it { expect(blob.analyzed?).to be_truthy }
|
it { expect(blob.analyzed?).to be_truthy }
|
||||||
it { expect(blob.lock_version).to eq(2) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "should raise ActiveRecord::StaleObjectError" do
|
|
||||||
let(:blob_2) { ActiveStorage::Blob.find(blob.id) }
|
|
||||||
before do
|
|
||||||
blob_2.virus_scan_result = ActiveStorage::VirusScanner::INFECTED
|
|
||||||
blob.virus_scan_result = ActiveStorage::VirusScanner::SAFE
|
|
||||||
blob.save
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect { blob_2.save }.to raise_error(ActiveRecord::StaleObjectError) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an integrity error" do
|
context "when there is an integrity error" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue