diff --git a/Gemfile b/Gemfile index 51219ddd..aa411461 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "pg" gem "plek" gem "sentry-sidekiq" gem "sidekiq-scheduler" -gem "sidekiq-unique-jobs" +gem "sidekiq-unique-jobs", "< 8.0.8" group :development, :test do gem "brakeman" diff --git a/Gemfile.lock b/Gemfile.lock index 9258b300..e9afe57d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,9 +84,6 @@ GEM msgpack (~> 1.2) brakeman (6.2.1) racc - brpoplpush-redis_script (0.1.3) - concurrent-ruby (~> 1.0, >= 1.0.5) - redis (>= 1.0, < 6) builder (3.3.0) byebug (11.1.3) climate_control (1.2.0) @@ -134,7 +131,7 @@ GEM fugit (1.11.1) et-orbi (~> 1, >= 1.2.11) raabro (~> 1.4) - gds-api-adapters (96.0.1) + gds-api-adapters (96.0.3) addressable link_header null_logger @@ -177,16 +174,15 @@ GEM sentry-rails (~> 5.3) sentry-ruby (~> 5.3) statsd-ruby (~> 1.5) - govuk_sidekiq (8.0.1) + govuk_sidekiq (9.0.0) gds-api-adapters (>= 19.1.0) govuk_app_config (>= 1.1) - redis (< 5) - redis-namespace (~> 1.6) - sidekiq (~> 6.5, >= 6.5.12) + redis-client (>= 0.22.2) + sidekiq (~> 7.0, < 8) hashdiff (1.1.0) hashie (5.0.0) http-accept (1.7.0) - http-cookie (1.0.6) + http-cookie (1.0.7) domain_name (~> 0.5) httparty (0.22.0) csv @@ -222,7 +218,7 @@ GEM method_source (1.0.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0604) + mime-types-data (3.2024.0903) mini_mime (1.1.5) mini_portile2 (2.8.7) minitest (5.25.1) @@ -508,7 +504,7 @@ GEM method_source (~> 1.0) psych (5.1.2) stringio - public_suffix (6.0.0) + public_suffix (6.0.1) puma (6.4.3) nio4r (~> 2.0) raabro (1.4.0) @@ -562,9 +558,8 @@ GEM ffi (~> 1.0) rdoc (6.7.0) psych (>= 4.0.0) - redis (4.8.1) - redis-namespace (1.11.0) - redis (>= 4) + redis-client (0.22.2) + connection_pool regexp_parser (2.9.2) reline (0.5.10) io-console (~> 0.5) @@ -650,20 +645,20 @@ GEM sentry-sidekiq (5.19.0) sentry-ruby (~> 5.19.0) sidekiq (>= 3.0) - sidekiq (6.5.12) - connection_pool (>= 2.2.5, < 3) - rack (~> 2.0) - redis (>= 4.5.0, < 5) + sidekiq (7.3.2) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) sidekiq-scheduler (5.0.6) rufus-scheduler (~> 3.2) sidekiq (>= 6, < 8) tilt (>= 1.4.0, < 3) - sidekiq-unique-jobs (7.1.33) - brpoplpush-redis_script (> 0.1.1, <= 2.0.0) + sidekiq-unique-jobs (8.0.7) concurrent-ruby (~> 1.0, >= 1.0.5) - redis (< 5.0) - sidekiq (>= 5.0, < 7.0) - thor (>= 0.20, < 3.0) + sidekiq (>= 7.0.0, < 8.0.0) + thor (>= 1.0, < 3.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -745,7 +740,7 @@ DEPENDENCIES rubocop-govuk sentry-sidekiq sidekiq-scheduler - sidekiq-unique-jobs + sidekiq-unique-jobs (< 8.0.8) simplecov timecop web-console diff --git a/app/controllers/batch_controller.rb b/app/controllers/batch_controller.rb index d51b76b8..cb8e9c12 100644 --- a/app/controllers/batch_controller.rb +++ b/app/controllers/batch_controller.rb @@ -48,7 +48,7 @@ def create render(json: batch_report(batch), status: :created) else batch.checks.each do |check| - CheckWorker.run(check.id, priority: create_params.priority) + CheckJob.run(check.id, priority: create_params.priority) end render(json: batch_report(batch.reload), status: :accepted) diff --git a/app/controllers/check_controller.rb b/app/controllers/check_controller.rb index 3ff16bfe..00fac8ee 100644 --- a/app/controllers/check_controller.rb +++ b/app/controllers/check_controller.rb @@ -36,7 +36,7 @@ def check check = Check.create!(link:) - CheckWorker.run( + CheckJob.run( check.id, priority: check_params.priority, synchronous: check_params.synchronous, diff --git a/app/models/batch.rb b/app/models/batch.rb index 8f466233..b8318c58 100644 --- a/app/models/batch.rb +++ b/app/models/batch.rb @@ -23,7 +23,7 @@ def trigger_webhook return unless completed? return if webhook_triggered - WebhookWorker.perform_async( + WebhookJob.perform_async( BatchPresenter.new(self).report.to_json, webhook_uri, webhook_secret_token, diff --git a/app/workers/check_worker.rb b/app/sidekiq/check_job.rb similarity index 95% rename from app/workers/check_worker.rb rename to app/sidekiq/check_job.rb index 6c1ceeb3..823b418e 100644 --- a/app/workers/check_worker.rb +++ b/app/sidekiq/check_job.rb @@ -1,5 +1,5 @@ -class CheckWorker - include Sidekiq::Worker +class CheckJob + include Sidekiq::Job include PerformAsyncInQueue sidekiq_options retry: 3, lock: :until_and_while_executing, lock_args_method: :unique_args @@ -56,3 +56,5 @@ def self.run(check_id, priority: "high", synchronous: false) end end end + +CheckWorker = CheckJob diff --git a/app/workers/cleanup_worker.rb b/app/sidekiq/cleanup_job.rb similarity index 80% rename from app/workers/cleanup_worker.rb rename to app/sidekiq/cleanup_job.rb index 3f5d18ec..d50789be 100644 --- a/app/workers/cleanup_worker.rb +++ b/app/sidekiq/cleanup_job.rb @@ -1,11 +1,11 @@ require "sidekiq-scheduler" -class CleanupWorker - include Sidekiq::Worker +class CleanupJob + include Sidekiq::Job def perform checks_to_perform.each do |check_id| - CheckWorker.perform_async(check_id) + CheckJob.perform_async(check_id) end old_batches.delete_all @@ -28,3 +28,5 @@ def old_batches Batch.where(id: BatchCheck.select(:batch_id).where(check: old_checks)) end end + +CleanupWorker = CleanupJob diff --git a/app/workers/webhook_worker.rb b/app/sidekiq/webhook_job.rb similarity index 88% rename from app/workers/webhook_worker.rb rename to app/sidekiq/webhook_job.rb index a2a748d6..a647ba7a 100644 --- a/app/workers/webhook_worker.rb +++ b/app/sidekiq/webhook_job.rb @@ -1,8 +1,8 @@ -class RestartWorkerException < RuntimeError +class RestartJobException < RuntimeError end -class WebhookWorker - include Sidekiq::Worker +class WebhookJob + include Sidekiq::Job sidekiq_options queue: :webhooks, retry: 4, lock: :until_and_while_executing, lock_args_method: :unique_args @@ -25,7 +25,7 @@ def perform(report, uri, secret_token, batch_id) connection.post do |req| req.url uri req.headers["Content-Type"] = "application/json" - req.headers["User-Agent"] = "#{ENV.fetch('GOVUK_APP_NAME', 'link-checker-api')} (webhook-worker)" + req.headers["User-Agent"] = "#{ENV.fetch('GOVUK_APP_NAME', 'link-checker-api')} (webhook-job)" req.headers[SIGNATURE_HEADER] = generate_signature(report, secret_token) if secret_token req.body = report end @@ -33,7 +33,7 @@ def perform(report, uri, secret_token, batch_id) batch.update!(webhook_triggered: true) rescue Faraday::ClientError => e logger.error e.message - raise RestartWorkerException + raise RestartJobException rescue Faraday::ServerError => e logger.error e.message end @@ -49,3 +49,5 @@ def generate_signature(body, key) OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), key, body) end end + +WebhookWorker = WebhookJob diff --git a/config/initializers/govuk_error.rb b/config/initializers/govuk_error.rb index f3e3e5ef..f471171a 100644 --- a/config/initializers/govuk_error.rb +++ b/config/initializers/govuk_error.rb @@ -2,6 +2,6 @@ config.data_sync_excluded_exceptions += %w[ Faraday::ServerError Faraday::ConnectionFailed - RestartWorkerException + RestartJobException ] end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 0850da6a..a844a03b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -19,6 +19,3 @@ # SidekiqUniqueJobs recommends not testing this behaviour, our tests have previously has caused flakey builds SidekiqUniqueJobs.config.enabled = !Rails.env.test? SidekiqUniqueJobs.config.logger_enabled = !Rails.env.test? - -# Use Sidekiq strict args to force Sidekiq 6 deprecations to error ahead of upgrade to Sidekiq 7 -Sidekiq.strict_args! diff --git a/config/sidekiq.yml b/config/sidekiq.yml index e6ff3171..597d427f 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -8,4 +8,4 @@ :schedule: cleanup: every: 60m - class: CleanupWorker + class: CleanupJob diff --git a/spec/requests/batch_spec.rb b/spec/requests/batch_spec.rb index 26f1d83f..b6f78d02 100644 --- a/spec/requests/batch_spec.rb +++ b/spec/requests/batch_spec.rb @@ -40,7 +40,7 @@ include_examples "returns batch report" it "creates a job" do - expect(CheckWorker.jobs.size).to eq(2) + expect(CheckJob.jobs.size).to eq(2) end end diff --git a/spec/workers/check_worker_spec.rb b/spec/workers/check_job_spec.rb similarity index 98% rename from spec/workers/check_worker_spec.rb rename to spec/workers/check_job_spec.rb index e5ae7135..89a4d2a8 100644 --- a/spec/workers/check_worker_spec.rb +++ b/spec/workers/check_job_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe CheckWorker do +RSpec.describe CheckJob do specify { expect(described_class).to have_valid_sidekiq_options } describe "perform" do diff --git a/spec/workers/cleanup_worker_spec.rb b/spec/workers/cleanup_job_spec.rb similarity index 96% rename from spec/workers/cleanup_worker_spec.rb rename to spec/workers/cleanup_job_spec.rb index 6aa4ec80..199fa1ba 100644 --- a/spec/workers/cleanup_worker_spec.rb +++ b/spec/workers/cleanup_job_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe CleanupWorker do +RSpec.describe CleanupJob do describe "perform" do let(:link1) { create(:link, id: 1) } let(:link2) { create(:link, id: 2) } diff --git a/spec/workers/webhook_worker_spec.rb b/spec/workers/webhook_job_spec.rb similarity index 98% rename from spec/workers/webhook_worker_spec.rb rename to spec/workers/webhook_job_spec.rb index 8f9dd193..73c4314f 100644 --- a/spec/workers/webhook_worker_spec.rb +++ b/spec/workers/webhook_job_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe WebhookWorker do +RSpec.describe WebhookJob do specify { expect(described_class).to have_valid_sidekiq_options } describe "perform" do