refactor(virus_scan): remove lock

This commit is contained in:
Paul Chavard 2022-12-22 20:55:15 +01:00
parent 6e18090fb3
commit c4a30084fe
5 changed files with 3 additions and 25 deletions

View file

@ -10,7 +10,7 @@ class Champs::PieceJustificativeController < ApplicationController
end
def update
if attach_piece_justificative_or_retry
if attach_piece_justificative
render :show
else
render json: { errors: @champ.errors.full_messages }, status: 422
@ -46,10 +46,4 @@ class Champs::PieceJustificativeController < ApplicationController
save_succeed
end
def attach_piece_justificative_or_retry
attach_piece_justificative
rescue ActiveRecord::StaleObjectError
attach_piece_justificative
end
end

View file

@ -5,8 +5,7 @@ module ActiveJob::RetryOnTransientErrors
Excon::Error::InternalServerError,
Excon::Error::GatewayTimeout,
Excon::Error::BadRequest,
Excon::Error::Socket,
ActiveRecord::StaleObjectError
Excon::Error::Socket
]
included do

View file

@ -2,6 +2,7 @@ module BlobVirusScannerConcern
extend ActiveSupport::Concern
included do
self.ignored_columns = [:lock_version]
before_create :set_pending
end

View file

@ -36,14 +36,10 @@ class CommentaireService
def self.save(dossier, params)
build_and_save(dossier, params)
rescue ActiveRecord::StaleObjectError
build_and_save(dossier, params)
end
def self.save!(dossier, params)
build_and_save(dossier, params, raise_exception: true)
rescue ActiveRecord::StaleObjectError
build_and_save(dossier, params, raise_exception: true)
end
def self.build_and_save(dossier, params, raise_exception: false)

View file

@ -15,18 +15,6 @@ describe VirusScannerJob, type: :job do
end
it { expect(blob.virus_scanner.safe?).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
context "when there is an integrity error" do