demarches-normaliennes/app/jobs/virus_scanner_job.rb
Pierre de La Morinerie 08094e5384 jobs: retry on ActiveStorage::IntegrityError during virus scan
This is the same setting than what ActiveStorage::AnalyzeJob uses.
2021-03-16 10:52:12 +01:00

20 lines
691 B
Ruby

class VirusScannerJob < ApplicationJob
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 for some reason the file appears invalid, retry for a while
retry_on ActiveStorage::IntegrityError, attempts: 10, wait: 5.seconds
def perform(blob)
metadata = extract_metadata_via_virus_scanner(blob)
blob.update!(metadata: blob.metadata.merge(metadata))
end
def extract_metadata_via_virus_scanner(blob)
ActiveStorage::VirusScanner.new(blob).metadata
end
end