2019-05-02 11:37:35 +02:00
|
|
|
class VirusScannerJob < ApplicationJob
|
2020-07-13 17:48:09 +02:00
|
|
|
queue_as :active_storage_analysis
|
|
|
|
|
2020-09-03 11:00:59 +02:00
|
|
|
# If by the time the job runs the blob has been deleted, ignore the error
|
2020-07-13 14:31:21 +02:00
|
|
|
discard_on ActiveRecord::RecordNotFound
|
2020-09-03 11:00:59 +02:00
|
|
|
# If the file is deleted during the scan, ignore the error
|
|
|
|
discard_on ActiveStorage::FileNotFoundError
|
2020-07-13 14:31:21 +02:00
|
|
|
|
2021-03-11 18:36:25 +01:00
|
|
|
# If for some reason the file appears invalid, retry for a while
|
|
|
|
retry_on ActiveStorage::IntegrityError, attempts: 10, wait: 5.seconds
|
|
|
|
|
2019-05-02 11:37:35 +02:00
|
|
|
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
|