From b759c9f00e09836adb94c2bd22613f52018fd11c Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Mon, 23 Sep 2024 11:50:42 +0100 Subject: [PATCH] Rename `SaveToCloudStorageWorker` `Sidekiq::Worker` has been deprecated in Sidekiq 7, so we need to replace it with `Sidekiq::Job`, and then rename the workers to be jobs. --- app/models/asset.rb | 2 +- .../save_to_cloud_storage_job.rb} | 4 ++-- spec/models/asset_spec.rb | 6 +++--- spec/requests/virus_scanning_spec.rb | 2 +- .../save_to_cloud_storage_job_spec.rb} | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename app/{workers/save_to_cloud_storage_worker.rb => sidekiq/save_to_cloud_storage_job.rb} (78%) rename spec/{workers/save_to_cloud_storage_worker_spec.rb => sidekiq/save_to_cloud_storage_job_spec.rb} (96%) diff --git a/app/models/asset.rb b/app/models/asset.rb index f0c0b983..78f9dab1 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -95,7 +95,7 @@ class Asset end after_transition to: :clean do |asset, _| - SaveToCloudStorageWorker.perform_async(asset.id.to_s) + SaveToCloudStorageJob.perform_async(asset.id.to_s) end event :scanned_infected do diff --git a/app/workers/save_to_cloud_storage_worker.rb b/app/sidekiq/save_to_cloud_storage_job.rb similarity index 78% rename from app/workers/save_to_cloud_storage_worker.rb rename to app/sidekiq/save_to_cloud_storage_job.rb index ef10f758..fffae7a4 100644 --- a/app/workers/save_to_cloud_storage_worker.rb +++ b/app/sidekiq/save_to_cloud_storage_job.rb @@ -1,7 +1,7 @@ require "services" -class SaveToCloudStorageWorker - include Sidekiq::Worker +class SaveToCloudStorageJob + include Sidekiq::Job def perform(asset_id) asset = Asset.undeleted.find(asset_id) diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb index 4970541b..9136b9e8 100644 --- a/spec/models/asset_spec.rb +++ b/spec/models/asset_spec.rb @@ -503,7 +503,7 @@ let(:asset) { FactoryBot.build(:asset, state:) } before do - allow(SaveToCloudStorageWorker).to receive(:perform_async) + allow(SaveToCloudStorageJob).to receive(:perform_async) end it "sets the asset state to clean" do @@ -513,7 +513,7 @@ end it "schedules saving the asset to cloud storage" do - expect(SaveToCloudStorageWorker).to receive(:perform_async).with(asset.id) + expect(SaveToCloudStorageJob).to receive(:perform_async).with(asset.id) asset.scanned_clean! end @@ -551,7 +551,7 @@ let(:asset) { FactoryBot.build(:asset, state:) } it "does not schedule saving the asset to cloud storage" do - expect(SaveToCloudStorageWorker).not_to receive(:perform_async).with(asset.id) + expect(SaveToCloudStorageJob).not_to receive(:perform_async).with(asset.id) asset.scanned_infected! end diff --git a/spec/requests/virus_scanning_spec.rb b/spec/requests/virus_scanning_spec.rb index a40df07c..55730125 100644 --- a/spec/requests/virus_scanning_spec.rb +++ b/spec/requests/virus_scanning_spec.rb @@ -27,7 +27,7 @@ get download_media_path(id: asset, filename: "lorem.txt") expect(response).to have_http_status(:not_found) - SaveToCloudStorageWorker.drain + SaveToCloudStorageJob.drain get download_media_path(id: asset, filename: "lorem.txt") expect(response).to have_http_status(:found) diff --git a/spec/workers/save_to_cloud_storage_worker_spec.rb b/spec/sidekiq/save_to_cloud_storage_job_spec.rb similarity index 96% rename from spec/workers/save_to_cloud_storage_worker_spec.rb rename to spec/sidekiq/save_to_cloud_storage_job_spec.rb index b676a8a3..ba90f3b1 100644 --- a/spec/workers/save_to_cloud_storage_worker_spec.rb +++ b/spec/sidekiq/save_to_cloud_storage_job_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe SaveToCloudStorageWorker, type: :worker do +RSpec.describe SaveToCloudStorageJob, type: :worker do let(:worker) { described_class.new } describe "#perform" do