From b65c320be77a8e6f9f17a5a26783a043afcd0927 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:16:24 +0000 Subject: [PATCH 1/8] Bump govuk_sidekiq from 8.0.1 to 9.0.1 Bumps [govuk_sidekiq](https://github.com/alphagov/govuk_sidekiq) from 8.0.1 to 9.0.1. - [Changelog](https://github.com/alphagov/govuk_sidekiq/blob/main/CHANGELOG.md) - [Commits](https://github.com/alphagov/govuk_sidekiq/compare/v8.0.1...v9.0.1) --- updated-dependencies: - dependency-name: govuk_sidekiq dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 420d74a9..ab0689e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -176,12 +176,11 @@ GEM sentry-rails (~> 5.3) sentry-ruby (~> 5.3) statsd-ruby (~> 1.5) - govuk_sidekiq (8.0.1) + govuk_sidekiq (9.0.1) 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.1) hashie (5.0.0) http-accept (1.7.0) @@ -240,9 +239,10 @@ GEM rack (>= 2.1.4.1) marcel (1.0.4) method_source (1.1.0) - mime-types (3.5.2) + mime-types (3.6.0) + logger mime-types-data (~> 3.2015) - mime-types-data (3.2024.0820) + mime-types-data (3.2024.1001) mini_mime (1.1.5) mini_portile2 (2.8.7) minitest (5.25.1) @@ -584,9 +584,10 @@ GEM ffi (~> 1.0) rdoc (6.7.0) psych (>= 4.0.0) - redis (4.8.1) - redis-namespace (1.11.0) - redis (>= 4) + redis (5.3.0) + redis-client (>= 0.22.0) + redis-client (0.22.2) + connection_pool regexp_parser (2.9.2) reline (0.5.10) io-console (~> 0.5) @@ -664,10 +665,12 @@ GEM sidekiq (>= 3.0) shoulda-matchers (6.4.0) activesupport (>= 5.2.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) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) From 65e4f43697e92ad58c76b7fdd54adae69a133618 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:32:47 +0100 Subject: [PATCH 2/8] Rename `ContentImprovementFeedbackWorker` -> `ContentImprovementFeedbackJob` Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../anonymous_feedback/content_improvement_controller.rb | 2 +- app/sidekiq/content_improvement_feedback_job.rb | 9 +++++++++ app/workers/content_improvement_feedback_worker.rb | 7 ------- 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 app/sidekiq/content_improvement_feedback_job.rb delete mode 100644 app/workers/content_improvement_feedback_worker.rb diff --git a/app/controllers/anonymous_feedback/content_improvement_controller.rb b/app/controllers/anonymous_feedback/content_improvement_controller.rb index cc2c67f3..1ec7eddd 100644 --- a/app/controllers/anonymous_feedback/content_improvement_controller.rb +++ b/app/controllers/anonymous_feedback/content_improvement_controller.rb @@ -3,7 +3,7 @@ class ContentImprovementController < ApplicationController def create feedback = ContentImprovementFeedback.new(feedback_params) if feedback.valid? - ContentImprovementFeedbackWorker.perform_async(feedback_params) + ContentImprovementFeedbackJob.perform_async(feedback_params) head :accepted else render json: { "errors" => feedback.errors.to_a }, status: :unprocessable_entity diff --git a/app/sidekiq/content_improvement_feedback_job.rb b/app/sidekiq/content_improvement_feedback_job.rb new file mode 100644 index 00000000..73cfffde --- /dev/null +++ b/app/sidekiq/content_improvement_feedback_job.rb @@ -0,0 +1,9 @@ +class ContentImprovementFeedbackJob + include Sidekiq::Job + + def perform(feedback_params) + ContentImprovementFeedback.create!(feedback_params) + end +end + +ContentImprovementFeedbackWorker = ContentImprovementFeedbackJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/workers/content_improvement_feedback_worker.rb b/app/workers/content_improvement_feedback_worker.rb deleted file mode 100644 index 0824799b..00000000 --- a/app/workers/content_improvement_feedback_worker.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ContentImprovementFeedbackWorker - include Sidekiq::Worker - - def perform(feedback_params) - ContentImprovementFeedback.create!(feedback_params) - end -end From 7055a464c34ca4069de7b43ca2d9778444214726 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:36:18 +0100 Subject: [PATCH 3/8] Rename `ContentItemPopulateDoctypeWorker` -> `ContentItemPopulateDoctypeJob` Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../content_item_populate_doctype_job.rb} | 6 ++++-- ...171204155340_populate_document_type_for_content_items.rb | 2 +- .../content_item_populate_doctype_job_spec.rb} | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) rename app/{workers/content_item_populate_doctype_worker.rb => sidekiq/content_item_populate_doctype_job.rb} (74%) rename spec/{workers/content_item_populate_doctype_worker_spec.rb => sidekiq/content_item_populate_doctype_job_spec.rb} (93%) diff --git a/app/workers/content_item_populate_doctype_worker.rb b/app/sidekiq/content_item_populate_doctype_job.rb similarity index 74% rename from app/workers/content_item_populate_doctype_worker.rb rename to app/sidekiq/content_item_populate_doctype_job.rb index b876f23c..21035ae2 100644 --- a/app/workers/content_item_populate_doctype_worker.rb +++ b/app/sidekiq/content_item_populate_doctype_job.rb @@ -1,5 +1,5 @@ -class ContentItemPopulateDoctypeWorker - include Sidekiq::Worker +class ContentItemPopulateDoctypeJob + include Sidekiq::Job def perform content_store = GdsApi::ContentStore.new(Plek.find("content-store")) @@ -17,3 +17,5 @@ def perform Rails.logger.warn "There were errors with the following paths: #{document_type_errors.join(', ')}" end end + +ContentItemPopulateDoctypeWorker = ContentItemPopulateDoctypeJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/db/migrate/20171204155340_populate_document_type_for_content_items.rb b/db/migrate/20171204155340_populate_document_type_for_content_items.rb index 03a4948e..ab2bd98d 100644 --- a/db/migrate/20171204155340_populate_document_type_for_content_items.rb +++ b/db/migrate/20171204155340_populate_document_type_for_content_items.rb @@ -1,6 +1,6 @@ class PopulateDocumentTypeForContentItems < ActiveRecord::Migration[5.0] def up - ContentItemPopulateDoctypeWorker.perform_async + ContentItemPopulateDoctypeJob.perform_async end def down diff --git a/spec/workers/content_item_populate_doctype_worker_spec.rb b/spec/sidekiq/content_item_populate_doctype_job_spec.rb similarity index 93% rename from spec/workers/content_item_populate_doctype_worker_spec.rb rename to spec/sidekiq/content_item_populate_doctype_job_spec.rb index d515fdd5..8922a62e 100644 --- a/spec/workers/content_item_populate_doctype_worker_spec.rb +++ b/spec/sidekiq/content_item_populate_doctype_job_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require "gds_api/test_helpers/content_store" -describe ContentItemPopulateDoctypeWorker do +describe ContentItemPopulateDoctypeJob do include GdsApi::TestHelpers::ContentStore it "updates every content item's `document_type`" do From 95c5a752e00325afc4e1ef4cd459b7c075a43dee Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:40:31 +0100 Subject: [PATCH 4/8] Rename `ServiceFeedbackWorker` -> ServiceFeedbackJob Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../anonymous_feedback/service_feedback_controller.rb | 2 +- app/sidekiq/service_feedback_job.rb | 9 +++++++++ app/workers/service_feedback_worker.rb | 7 ------- 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 app/sidekiq/service_feedback_job.rb delete mode 100644 app/workers/service_feedback_worker.rb diff --git a/app/controllers/anonymous_feedback/service_feedback_controller.rb b/app/controllers/anonymous_feedback/service_feedback_controller.rb index 0ec43641..40682a54 100644 --- a/app/controllers/anonymous_feedback/service_feedback_controller.rb +++ b/app/controllers/anonymous_feedback/service_feedback_controller.rb @@ -4,7 +4,7 @@ def create request = ServiceFeedback.new(service_feedback_params) if request.valid? - ServiceFeedbackWorker.perform_async(service_feedback_params) + ServiceFeedbackJob.perform_async(service_feedback_params) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity diff --git a/app/sidekiq/service_feedback_job.rb b/app/sidekiq/service_feedback_job.rb new file mode 100644 index 00000000..e7bf365e --- /dev/null +++ b/app/sidekiq/service_feedback_job.rb @@ -0,0 +1,9 @@ +class ServiceFeedbackJob + include Sidekiq::Job + + def perform(service_feedback_params) + ServiceFeedback.new(service_feedback_params).save! + end +end + +ServiceFeedbackWorker = ServiceFeedbackJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/workers/service_feedback_worker.rb b/app/workers/service_feedback_worker.rb deleted file mode 100644 index 5393e78a..00000000 --- a/app/workers/service_feedback_worker.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ServiceFeedbackWorker - include Sidekiq::Worker - - def perform(service_feedback_params) - ServiceFeedback.new(service_feedback_params).save! - end -end From 549f88cc00d77a790c4265f6ac2b969960b87433 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:42:12 +0100 Subject: [PATCH 5/8] Rename `GenerateFeedbackCsvWorker` -> `GenerateFeedbackCsvJob` Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../anonymous_feedback/export_requests_controller.rb | 2 +- .../generate_feedback_csv_job.rb} | 6 ++++-- .../anonymous_feedback/export_requests_controller_spec.rb | 6 +++--- .../generate_feedback_csv_job_spec.rb} | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) rename app/{workers/generate_feedback_csv_worker.rb => sidekiq/generate_feedback_csv_job.rb} (80%) rename spec/models/{workers/generate_feedback_csv_worker_spec.rb => sidekiq/generate_feedback_csv_job_spec.rb} (95%) diff --git a/app/controllers/anonymous_feedback/export_requests_controller.rb b/app/controllers/anonymous_feedback/export_requests_controller.rb index 704d62f0..54b92063 100644 --- a/app/controllers/anonymous_feedback/export_requests_controller.rb +++ b/app/controllers/anonymous_feedback/export_requests_controller.rb @@ -5,7 +5,7 @@ def create export_request = FeedbackExportRequest.new(export_request_params) if export_request.save - GenerateFeedbackCsvWorker.perform_async(export_request.id) + GenerateFeedbackCsvJob.perform_async(export_request.id) head :accepted else render json: { "errors" => export_request.errors.to_a }, status: :unprocessable_entity diff --git a/app/workers/generate_feedback_csv_worker.rb b/app/sidekiq/generate_feedback_csv_job.rb similarity index 80% rename from app/workers/generate_feedback_csv_worker.rb rename to app/sidekiq/generate_feedback_csv_job.rb index 7f723b59..d3b049ce 100644 --- a/app/workers/generate_feedback_csv_worker.rb +++ b/app/sidekiq/generate_feedback_csv_job.rb @@ -1,7 +1,7 @@ require "s3_file_uploader" -class GenerateFeedbackCsvWorker - include Sidekiq::Worker +class GenerateFeedbackCsvJob + include Sidekiq::Job def initialize(uploader: S3FileUploader.new) @uploader = uploader @@ -23,3 +23,5 @@ def perform(*args) ExportNotification.notification_email(feedback_export_request.notification_email, feedback_export_request.url).deliver_now end end + +GenerateFeedbackCsvWorker = GenerateFeedbackCsvJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/spec/controllers/anonymous_feedback/export_requests_controller_spec.rb b/spec/controllers/anonymous_feedback/export_requests_controller_spec.rb index 1ec25ed9..c3f7430e 100644 --- a/spec/controllers/anonymous_feedback/export_requests_controller_spec.rb +++ b/spec/controllers/anonymous_feedback/export_requests_controller_spec.rb @@ -6,7 +6,7 @@ context "posted with valid parameters" do before do - expect(GenerateFeedbackCsvWorker).to receive(:perform_async).once.with(instance_of(Integer)) + expect(GenerateFeedbackCsvJob).to receive(:perform_async).once.with(instance_of(Integer)) post :create, params: { export_request: { @@ -40,7 +40,7 @@ context "posted with invalid parameters" do before do - expect(GenerateFeedbackCsvWorker).to receive(:perform_async).never + expect(GenerateFeedbackCsvJob).to receive(:perform_async).never post :create, params: { export_request: { @@ -60,7 +60,7 @@ context "with backwards compatible `path_prefix` param" do before do - expect(GenerateFeedbackCsvWorker).to receive(:perform_async).once.with(instance_of(Integer)) + expect(GenerateFeedbackCsvJob).to receive(:perform_async).once.with(instance_of(Integer)) post :create, params: { export_request: diff --git a/spec/models/workers/generate_feedback_csv_worker_spec.rb b/spec/models/sidekiq/generate_feedback_csv_job_spec.rb similarity index 95% rename from spec/models/workers/generate_feedback_csv_worker_spec.rb rename to spec/models/sidekiq/generate_feedback_csv_job_spec.rb index 980fe872..6b73bfbf 100644 --- a/spec/models/workers/generate_feedback_csv_worker_spec.rb +++ b/spec/models/sidekiq/generate_feedback_csv_job_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe GenerateFeedbackCsvWorker, type: :worker do +describe GenerateFeedbackCsvJob, type: :worker do describe "#perform" do let(:feedback_export_request) { create(:feedback_export_request) } let(:uploader) { instance_double(S3FileUploader) } From ea8362904262c67f0ec01fa93cde1ba1ca85318a Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:43:47 +0100 Subject: [PATCH 6/8] Rename `GenerateFeedbackCsvWorker` -> `GenerateFeedbackCsvJob` Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../anonymous_feedback/global_export_requests_controller.rb | 2 +- .../generate_global_export_csv_job.rb} | 6 ++++-- .../global_export_requests_controller_spec.rb | 4 ++-- .../generate_global_export_csv_job_spec.rb} | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) rename app/{workers/generate_global_export_csv_worker.rb => sidekiq/generate_global_export_csv_job.rb} (81%) rename spec/{workers/generate_global_export_csv_worker_spec.rb => sidekiq/generate_global_export_csv_job_spec.rb} (93%) diff --git a/app/controllers/anonymous_feedback/global_export_requests_controller.rb b/app/controllers/anonymous_feedback/global_export_requests_controller.rb index 02414404..a485a8a1 100644 --- a/app/controllers/anonymous_feedback/global_export_requests_controller.rb +++ b/app/controllers/anonymous_feedback/global_export_requests_controller.rb @@ -4,7 +4,7 @@ class AnonymousFeedback::GlobalExportRequestsController < ApplicationController def create export_request = GlobalExportRequest.new(global_export_request_params) if export_request.valid? - GenerateGlobalExportCsvWorker.perform_async(global_export_request_params) + GenerateGlobalExportCsvJob.perform_async(global_export_request_params) head :accepted else render json: { "errors" => export_request.errors.to_a }, status: :unprocessable_entity diff --git a/app/workers/generate_global_export_csv_worker.rb b/app/sidekiq/generate_global_export_csv_job.rb similarity index 81% rename from app/workers/generate_global_export_csv_worker.rb rename to app/sidekiq/generate_global_export_csv_job.rb index 331bfc4b..717f033e 100644 --- a/app/workers/generate_global_export_csv_worker.rb +++ b/app/sidekiq/generate_global_export_csv_job.rb @@ -1,7 +1,7 @@ require "s3_file_uploader" -class GenerateGlobalExportCsvWorker - include Sidekiq::Worker +class GenerateGlobalExportCsvJob + include Sidekiq::Job def initialize(uploader: S3FileUploader.new) @uploader = uploader @@ -26,3 +26,5 @@ def perform(export_params) GlobalExportNotification.notification_email(export_params["notification_email"], feedback_export_request.url).deliver_now end end + +GenerateGlobalExportCsvWorker = GenerateGlobalExportCsvJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb b/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb index a9ab507c..48ab9cc8 100644 --- a/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb +++ b/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb @@ -6,7 +6,7 @@ context "with valid parameters" do it "succeeds" do - expect(GenerateGlobalExportCsvWorker).to receive(:perform_async).once + expect(GenerateGlobalExportCsvJob).to receive(:perform_async).once response = post :create, params: { @@ -24,7 +24,7 @@ context "with invalid parameters" do it "fails" do - expect(GenerateGlobalExportCsvWorker).not_to receive(:perform_async) + expect(GenerateGlobalExportCsvJob).not_to receive(:perform_async) response = post :create, params: { diff --git a/spec/workers/generate_global_export_csv_worker_spec.rb b/spec/sidekiq/generate_global_export_csv_job_spec.rb similarity index 93% rename from spec/workers/generate_global_export_csv_worker_spec.rb rename to spec/sidekiq/generate_global_export_csv_job_spec.rb index b70bc955..e2e61a7d 100644 --- a/spec/workers/generate_global_export_csv_worker_spec.rb +++ b/spec/sidekiq/generate_global_export_csv_job_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require "date" -describe GenerateGlobalExportCsvWorker, type: :worker do +describe GenerateGlobalExportCsvJob, type: :worker do let(:uploader) { instance_double(S3FileUploader) } subject(:worker) { described_class.new(uploader:) } From bfed416ccabec4aeab147d031789e89ae5d82ab6 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:46:23 +0100 Subject: [PATCH 7/8] Rename ContentItemEnrichment, LongFormContact, ProblemReport, ZendeskTicket workers Sidekiq::Worker has been deprecated in Sidekiq 7. This replaces all instances of Sidekiq::Worker with Sidekiq::Job and renames/moves workers to app/sidekiq/MyJob.rb. --- .../long_form_contact_controller.rb | 2 +- .../anonymous_feedback/problem_reports_controller.rb | 2 +- .../content_item_enrichment_job.rb} | 6 ++++-- app/sidekiq/long_form_contact_job.rb | 10 ++++++++++ app/sidekiq/problem_report_job.rb | 11 +++++++++++ .../zendesk_ticket_job.rb} | 6 ++++-- app/workers/long_form_contact_worker.rb | 8 -------- app/workers/problem_report_worker.rb | 9 --------- .../content_item_enrichment_job_spec.rb} | 4 ++-- .../content_item_enrichment_job_spec.rb} | 2 +- 10 files changed, 34 insertions(+), 26 deletions(-) rename app/{workers/content_item_enrichment_worker.rb => sidekiq/content_item_enrichment_job.rb} (82%) create mode 100644 app/sidekiq/long_form_contact_job.rb create mode 100644 app/sidekiq/problem_report_job.rb rename app/{workers/zendesk_ticket_worker.rb => sidekiq/zendesk_ticket_job.rb} (79%) delete mode 100644 app/workers/long_form_contact_worker.rb delete mode 100644 app/workers/problem_report_worker.rb rename spec/models/{workers/content_item_enrichment_worker_spec.rb => sidekiq/content_item_enrichment_job_spec.rb} (97%) rename spec/{workers/content_item_enrichment_worker_spec.rb => sidekiq/content_item_enrichment_job_spec.rb} (95%) diff --git a/app/controllers/anonymous_feedback/long_form_contact_controller.rb b/app/controllers/anonymous_feedback/long_form_contact_controller.rb index 05546b0c..2fb87544 100644 --- a/app/controllers/anonymous_feedback/long_form_contact_controller.rb +++ b/app/controllers/anonymous_feedback/long_form_contact_controller.rb @@ -4,7 +4,7 @@ def create request = LongFormContact.new(long_form_contact_params) if request.valid? - LongFormContactWorker.perform_async(long_form_contact_params) + LongFormContactJob.perform_async(long_form_contact_params) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity diff --git a/app/controllers/anonymous_feedback/problem_reports_controller.rb b/app/controllers/anonymous_feedback/problem_reports_controller.rb index 7cba909a..fbcb12ee 100644 --- a/app/controllers/anonymous_feedback/problem_reports_controller.rb +++ b/app/controllers/anonymous_feedback/problem_reports_controller.rb @@ -34,7 +34,7 @@ def create request = ProblemReport.new(problem_report_params) if request.valid? - ProblemReportWorker.perform_async(problem_report_params) + ProblemReportJob.perform_async(problem_report_params) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity diff --git a/app/workers/content_item_enrichment_worker.rb b/app/sidekiq/content_item_enrichment_job.rb similarity index 82% rename from app/workers/content_item_enrichment_worker.rb rename to app/sidekiq/content_item_enrichment_job.rb index 63eae1e9..a05fdf76 100644 --- a/app/workers/content_item_enrichment_worker.rb +++ b/app/sidekiq/content_item_enrichment_job.rb @@ -1,5 +1,5 @@ -class ContentItemEnrichmentWorker - include Sidekiq::Worker +class ContentItemEnrichmentJob + include Sidekiq::Job def perform(problem_report_id) problem_report = ProblemReport.find(problem_report_id) @@ -25,3 +25,5 @@ def build_orgs(org_hashes) end end end + +ContentItemEnrichmentWorker = ContentItemEnrichmentJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/sidekiq/long_form_contact_job.rb b/app/sidekiq/long_form_contact_job.rb new file mode 100644 index 00000000..f373ae20 --- /dev/null +++ b/app/sidekiq/long_form_contact_job.rb @@ -0,0 +1,10 @@ +class LongFormContactJob + include Sidekiq::Job + + def perform(long_form_contact_params) + contact = LongFormContact.create!(long_form_contact_params) + ZendeskTicketJob.perform_async(contact.id) + end +end + +LongFormContactWorker = LongFormContactJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/sidekiq/problem_report_job.rb b/app/sidekiq/problem_report_job.rb new file mode 100644 index 00000000..060d0895 --- /dev/null +++ b/app/sidekiq/problem_report_job.rb @@ -0,0 +1,11 @@ +class ProblemReportJob + include Sidekiq::Job + + def perform(problem_report_params) + problem_report = ProblemReport.create!(problem_report_params) + ZendeskTicketJob.perform_async(problem_report.id) + ContentItemEnrichmentJob.perform_async(problem_report.id) + end +end + +ProblemReportWorker = ProblemReportJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/workers/zendesk_ticket_worker.rb b/app/sidekiq/zendesk_ticket_job.rb similarity index 79% rename from app/workers/zendesk_ticket_worker.rb rename to app/sidekiq/zendesk_ticket_job.rb index 805509c2..08c5f9ef 100644 --- a/app/workers/zendesk_ticket_worker.rb +++ b/app/sidekiq/zendesk_ticket_job.rb @@ -1,8 +1,8 @@ require "zendesk/long_form_contact_ticket" require "zendesk/problem_report_ticket" -class ZendeskTicketWorker - include Sidekiq::Worker +class ZendeskTicketJob + include Sidekiq::Job def perform(anonymous_contact_id) anonymous_contact = AnonymousContact.find(anonymous_contact_id) @@ -19,3 +19,5 @@ def ticket_for(anonymous_contact) end end end + +ZendeskTicketWorker = ZendeskTicketJob ## TODO: Remove once queued jobs at the time of the upgrade are complete diff --git a/app/workers/long_form_contact_worker.rb b/app/workers/long_form_contact_worker.rb deleted file mode 100644 index 9ad7ffbe..00000000 --- a/app/workers/long_form_contact_worker.rb +++ /dev/null @@ -1,8 +0,0 @@ -class LongFormContactWorker - include Sidekiq::Worker - - def perform(long_form_contact_params) - contact = LongFormContact.create!(long_form_contact_params) - ZendeskTicketWorker.perform_async(contact.id) - end -end diff --git a/app/workers/problem_report_worker.rb b/app/workers/problem_report_worker.rb deleted file mode 100644 index 2e25d8cc..00000000 --- a/app/workers/problem_report_worker.rb +++ /dev/null @@ -1,9 +0,0 @@ -class ProblemReportWorker - include Sidekiq::Worker - - def perform(problem_report_params) - problem_report = ProblemReport.create!(problem_report_params) - ZendeskTicketWorker.perform_async(problem_report.id) - ContentItemEnrichmentWorker.perform_async(problem_report.id) - end -end diff --git a/spec/models/workers/content_item_enrichment_worker_spec.rb b/spec/models/sidekiq/content_item_enrichment_job_spec.rb similarity index 97% rename from spec/models/workers/content_item_enrichment_worker_spec.rb rename to spec/models/sidekiq/content_item_enrichment_job_spec.rb index 674c8c59..c457ed3a 100644 --- a/spec/models/workers/content_item_enrichment_worker_spec.rb +++ b/spec/models/sidekiq/content_item_enrichment_job_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" require "gds_api/test_helpers/content_store" -describe ContentItemEnrichmentWorker do +describe ContentItemEnrichmentJob do include GdsApi::TestHelpers::ContentStore - subject { ContentItemEnrichmentWorker.new } + subject { ContentItemEnrichmentJob.new } context "for a problem report about a piece of content we can't determine the organisation for" do let(:problem_report) { create(:problem_report, path: "/unknown-org-page") } diff --git a/spec/workers/content_item_enrichment_worker_spec.rb b/spec/sidekiq/content_item_enrichment_job_spec.rb similarity index 95% rename from spec/workers/content_item_enrichment_worker_spec.rb rename to spec/sidekiq/content_item_enrichment_job_spec.rb index f7a4bb78..14f25529 100644 --- a/spec/workers/content_item_enrichment_worker_spec.rb +++ b/spec/sidekiq/content_item_enrichment_job_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require "gds_api/test_helpers/content_store" -describe ContentItemEnrichmentWorker do +describe ContentItemEnrichmentJob do include GdsApi::TestHelpers::ContentStore let(:raw_path) { "my-magic-govuk-endpoint" } From c94cfacbc54ce299400a7dfe1c1a40b76f59ab35 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Fri, 18 Oct 2024 12:54:37 +0100 Subject: [PATCH 8/8] Make Sidekiq job arguments a hash (native JSON type) To ensure Sidekiq job arguments are native JSON type and to avoid ArgumentError. --- .../anonymous_feedback/long_form_contact_controller.rb | 2 +- .../anonymous_feedback/problem_reports_controller.rb | 2 +- .../anonymous_feedback/service_feedback_controller.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/anonymous_feedback/long_form_contact_controller.rb b/app/controllers/anonymous_feedback/long_form_contact_controller.rb index 2fb87544..8c15eea3 100644 --- a/app/controllers/anonymous_feedback/long_form_contact_controller.rb +++ b/app/controllers/anonymous_feedback/long_form_contact_controller.rb @@ -4,7 +4,7 @@ def create request = LongFormContact.new(long_form_contact_params) if request.valid? - LongFormContactJob.perform_async(long_form_contact_params) + LongFormContactJob.perform_async(long_form_contact_params.to_h) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity diff --git a/app/controllers/anonymous_feedback/problem_reports_controller.rb b/app/controllers/anonymous_feedback/problem_reports_controller.rb index fbcb12ee..c2fc3ed1 100644 --- a/app/controllers/anonymous_feedback/problem_reports_controller.rb +++ b/app/controllers/anonymous_feedback/problem_reports_controller.rb @@ -34,7 +34,7 @@ def create request = ProblemReport.new(problem_report_params) if request.valid? - ProblemReportJob.perform_async(problem_report_params) + ProblemReportJob.perform_async(problem_report_params.to_h) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity diff --git a/app/controllers/anonymous_feedback/service_feedback_controller.rb b/app/controllers/anonymous_feedback/service_feedback_controller.rb index 40682a54..901fbc9f 100644 --- a/app/controllers/anonymous_feedback/service_feedback_controller.rb +++ b/app/controllers/anonymous_feedback/service_feedback_controller.rb @@ -4,7 +4,7 @@ def create request = ServiceFeedback.new(service_feedback_params) if request.valid? - ServiceFeedbackJob.perform_async(service_feedback_params) + ServiceFeedbackJob.perform_async(service_feedback_params.to_h) head :accepted else render json: { "errors" => request.errors.to_a }, status: :unprocessable_entity