Skip to content

Commit

Permalink
Rename DeleteAssetFileFromNfsWorker
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
brucebolt committed Sep 24, 2024
1 parent bdea4dc commit 5eb7305
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Asset

after_transition to: :uploaded do |asset, _|
asset.save!
DeleteAssetFileFromNfsWorker.perform_in(5.minutes, asset.id.to_s)
DeleteAssetFileFromNfsJob.perform_in(5.minutes, asset.id.to_s)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class DeleteAssetFileFromNfsWorker
include Sidekiq::Worker
class DeleteAssetFileFromNfsJob
include Sidekiq::Job
sidekiq_options queue: "low_priority"

def perform(asset_id)
asset = Asset.find(asset_id)
if asset.uploaded?
FileUtils.rm_rf(File.dirname(asset.file.path))
Rails.logger.info("#{asset.id} - DeleteAssetFileFromNfsWorker - File removed")
Rails.logger.info("#{asset.id} - DeleteAssetFileFromNfsJob - File removed")
end
end
end
2 changes: 1 addition & 1 deletion config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"render_path": null,
"location": {
"type": "method",
"class": "DeleteAssetFileFromNfsWorker",
"class": "DeleteAssetFileFromNfsJob",
"method": "perform"
},
"user_input": "Asset.find(asset_id).file",
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/govuk_assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :govuk_assets do
task delete_file_from_nfs_for_assets_uploaded_to_s3: :environment do
processor = AssetProcessor.new(scope: Asset.where(state: "uploaded"))
processor.process_all_assets_with do |asset_id|
DeleteAssetFileFromNfsWorker.perform_async(asset_id.to_s)
DeleteAssetFileFromNfsJob.perform_async(asset_id.to_s)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@
end

it "triggers the delete asset file worker" do
expect(DeleteAssetFileFromNfsWorker).to receive(:perform_in)
expect(DeleteAssetFileFromNfsJob).to receive(:perform_in)
asset.upload_success!
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe DeleteAssetFileFromNfsWorker, type: :worker do
RSpec.describe DeleteAssetFileFromNfsJob, type: :worker do
subject(:worker) { described_class.new }

let(:asset) { FactoryBot.create(:asset, state:) }
Expand Down

0 comments on commit 5eb7305

Please sign in to comment.