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
|
|
|
|
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
|