diff --git a/app/models/asset.rb b/app/models/asset.rb index f8348045..f53c6147 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -243,7 +243,7 @@ def reset_state end def schedule_virus_scan - VirusScanWorker.perform_async(id.to_s) if unscanned? && redirect_url.blank? + VirusScanJob.perform_async(id.to_s) if unscanned? && redirect_url.blank? end def file_exists? diff --git a/app/workers/virus_scan_worker.rb b/app/sidekiq/virus_scan_job.rb similarity index 76% rename from app/workers/virus_scan_worker.rb rename to app/sidekiq/virus_scan_job.rb index 01abf553..6be9b368 100644 --- a/app/workers/virus_scan_worker.rb +++ b/app/sidekiq/virus_scan_job.rb @@ -1,7 +1,7 @@ require "services" -class VirusScanWorker - include Sidekiq::Worker +class VirusScanJob + include Sidekiq::Job sidekiq_options lock: :until_and_while_executing @@ -9,7 +9,7 @@ def perform(asset_id) asset = Asset.find(asset_id) if asset.unscanned? begin - Rails.logger.info("#{asset_id} - VirusScanWorker#perform - Virus scan started") + Rails.logger.info("#{asset_id} - VirusScanJob#perform - Virus scan started") Services.virus_scanner.scan(asset.file.path) asset.scanned_clean! rescue VirusScanner::InfectedFile => e diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb index 17db8ae2..d62bcf11 100644 --- a/spec/models/asset_spec.rb +++ b/spec/models/asset_spec.rb @@ -456,7 +456,7 @@ it "schedules a scan after create" do a = described_class.new(file: load_fixture_file("asset.png")) - expect(VirusScanWorker).to receive(:perform_async).with(a.id) + expect(VirusScanJob).to receive(:perform_async).with(a.id) a.save! end @@ -465,7 +465,7 @@ a = FactoryBot.create(:clean_asset) a.file = load_fixture_file("lorem.txt") - expect(VirusScanWorker).to receive(:perform_async).with(a.id) + expect(VirusScanJob).to receive(:perform_async).with(a.id) a.save! end @@ -475,7 +475,7 @@ original_filename = a.file.send(:original_filename) a.file = load_fixture_file("lorem.txt", named: original_filename) - expect(VirusScanWorker).to receive(:perform_async).with(a.id) + expect(VirusScanJob).to receive(:perform_async).with(a.id) a.save! end @@ -484,7 +484,7 @@ a = FactoryBot.create(:clean_asset) a.created_at = 5.days.ago - expect(VirusScanWorker).not_to receive(:perform_async) + expect(VirusScanJob).not_to receive(:perform_async) a.save! end @@ -492,7 +492,7 @@ it "does not schedule a scan if a redirect url is present" do a = FactoryBot.create(:asset, redirect_url: "/some-redirect") - expect(VirusScanWorker).not_to receive(:perform_async) + expect(VirusScanJob).not_to receive(:perform_async) a.save! end diff --git a/spec/requests/asset_requests_spec.rb b/spec/requests/asset_requests_spec.rb index 50727eec..6a621d4c 100644 --- a/spec/requests/asset_requests_spec.rb +++ b/spec/requests/asset_requests_spec.rb @@ -152,7 +152,7 @@ it "does not result in an invalid transition error when a redirect is received in short succession after a create" do # use threads to simulate multiple sidekiq workers threads = [] - allow(VirusScanWorker).to receive(:perform_async) do |asset_id| + allow(VirusScanJob).to receive(:perform_async) do |asset_id| threads << Thread.new do sleep(0.5) asset = Asset.find(asset_id) diff --git a/spec/requests/virus_scanning_spec.rb b/spec/requests/virus_scanning_spec.rb index a76ccec0..a40df07c 100644 --- a/spec/requests/virus_scanning_spec.rb +++ b/spec/requests/virus_scanning_spec.rb @@ -22,7 +22,7 @@ expect(response).to have_http_status(:not_found) allow(Services.virus_scanner).to receive(:scan) - VirusScanWorker.drain + VirusScanJob.drain get download_media_path(id: asset, filename: "lorem.txt") expect(response).to have_http_status(:not_found) diff --git a/spec/workers/virus_scan_worker_spec.rb b/spec/sidekiq/virus_scan_job_spec.rb similarity index 98% rename from spec/workers/virus_scan_worker_spec.rb rename to spec/sidekiq/virus_scan_job_spec.rb index f6a7831b..17a8c76c 100644 --- a/spec/workers/virus_scan_worker_spec.rb +++ b/spec/sidekiq/virus_scan_job_spec.rb @@ -2,7 +2,7 @@ require "services" require "sidekiq_unique_jobs/testing" -RSpec.describe VirusScanWorker do +RSpec.describe VirusScanJob do let(:worker) { described_class.new } let(:asset) { FactoryBot.create(:asset) } let(:scanner) { instance_double(VirusScanner) }