Merge pull request #5371 from betagouv/ignore-virus-scan-jobs-missing-files
Les jobs d'analyse anti-virus ne sont plus relancés si le fichier cible n'existe plus
This commit is contained in:
commit
640778641e
2 changed files with 22 additions and 3 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))
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
RSpec.describe VirusScannerJob, type: :job do
|
RSpec.describe VirusScannerJob, type: :job do
|
||||||
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
let(:champ) do
|
let(:champ) do
|
||||||
champ = create(:champ, :piece_justificative)
|
champ = create(:champ, :piece_justificative)
|
||||||
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||||
|
champ.save
|
||||||
champ
|
champ
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { VirusScannerJob.new.perform(champ.piece_justificative_file.blob) }
|
subject do
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
VirusScannerJob.perform_later(champ.piece_justificative_file.blob)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when no virus is found" do
|
context "when no virus is found" do
|
||||||
let(:virus_found?) { true }
|
let(:virus_found?) { true }
|
||||||
|
@ -15,7 +22,7 @@ RSpec.describe VirusScannerJob, type: :job do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(champ.piece_justificative_file.virus_scanner.safe?).to be_truthy }
|
it { expect(champ.reload.piece_justificative_file.virus_scanner.safe?).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a virus is found" do
|
context "when a virus is found" do
|
||||||
|
@ -26,6 +33,16 @@ RSpec.describe VirusScannerJob, type: :job do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(champ.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
it { expect(champ.reload.piece_justificative_file.virus_scanner.infected?).to be_truthy }
|
||||||
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue