add merge_and_update_metadata method

This commit is contained in:
simon lehericey 2021-04-06 18:00:54 +02:00
parent d552e364fc
commit e636e3a752

View file

@ -19,7 +19,7 @@ class VirusScannerJob < ApplicationJob
scanned_at: Time.zone.now scanned_at: Time.zone.now
} }
blob.update!(metadata: blob.metadata.merge(metadata)) merge_and_update_metadata(blob, metadata)
end end
def perform(blob) def perform(blob)
@ -27,10 +27,16 @@ class VirusScannerJob < ApplicationJob
if blob.virus_scanner.done? then return end if blob.virus_scanner.done? then return end
metadata = extract_metadata_via_virus_scanner(blob) metadata = extract_metadata_via_virus_scanner(blob)
blob.update!(metadata: blob.metadata.merge(metadata)) VirusScannerJob.merge_and_update_metadata(blob, metadata)
end end
def extract_metadata_via_virus_scanner(blob) def extract_metadata_via_virus_scanner(blob)
ActiveStorage::VirusScanner.new(blob).metadata ActiveStorage::VirusScanner.new(blob).metadata
end end
private
def self.merge_and_update_metadata(blob, metadata)
blob.update!(metadata: blob.metadata.merge(metadata))
end
end end