jobs: ignore missing blob during virus scan
We currently have many failed VirusScannerJob enqueued, because the
underlying blob is missing.
This PR fixes the issue by discarding the job in those cases (because if
the blob is gone, the job is never going to succeed).
The implementation is based on a similar issue encoutered by the
ActiveStorage::AnalyzeJob. See 06f8baf73c
This commit is contained in:
parent
b82c269cef
commit
7a67f1a802
2 changed files with 12 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
||||||
class VirusScannerJob < ApplicationJob
|
class VirusScannerJob < ApplicationJob
|
||||||
|
discard_on ActiveRecord::RecordNotFound
|
||||||
|
|
||||||
def perform(blob)
|
def perform(blob)
|
||||||
metadata = extract_metadata_via_virus_scanner(blob)
|
metadata = extract_metadata_via_virus_scanner(blob)
|
||||||
blob.update!(metadata: blob.metadata.merge(metadata))
|
blob.update!(metadata: blob.metadata.merge(metadata))
|
||||||
|
|
|
@ -35,4 +35,14 @@ RSpec.describe VirusScannerJob, type: :job do
|
||||||
|
|
||||||
it { expect(champ.reload.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
it { expect(champ.reload.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when the blob has been deleted" do
|
||||||
|
before do
|
||||||
|
Champ.find(champ.id).piece_justificative_file.purge
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores the error" do
|
||||||
|
expect { subject }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue