add the good retry_on StaleObjectError

This commit is contained in:
kara Diaby 2021-11-04 12:01:00 +01:00
parent 475bf0bd2d
commit 9ee9389ba1
2 changed files with 2 additions and 9 deletions

View file

@ -1,15 +1,8 @@
class VirusScannerJob < ApplicationJob
class FileNotAnalyzedYetError < StandardError
end
queue_as :active_storage_analysis
# If by the time the job runs the blob has been deleted, ignore the error
discard_on ActiveRecord::RecordNotFound
# If the file is deleted during the scan, ignore the error
discard_on ActiveStorage::FileNotFoundError
# If the file is not analyzed yet, retry later (to avoid clobbering metadata)
retry_on FileNotAnalyzedYetError, wait: :exponentially_longer, attempts: 10
# If for some reason the file appears invalid, retry for a while
retry_on(ActiveStorage::IntegrityError, attempts: 5, wait: 5.seconds) do |job, _error|
blob = job.arguments.first
@ -23,7 +16,6 @@ class VirusScannerJob < ApplicationJob
end
def perform(blob)
if !blob.analyzed? then raise FileNotAnalyzedYetError end
if blob.virus_scanner.done? then return end
metadata = extract_metadata_via_virus_scanner(blob)

View file

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