diff --git a/Gemfile.lock b/Gemfile.lock index 0b0baecc..484a45ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -212,11 +212,11 @@ GEM rouge sprockets (>= 3) sprockets-rails - govuk_sidekiq (7.1.3) + govuk_sidekiq (9.0.0) gds-api-adapters (>= 19.1.0) govuk_app_config (>= 1.1) - redis-namespace (~> 1.6) - sidekiq (~> 6.5) + redis-client (>= 0.22.2) + sidekiq (~> 7.0, < 8) govuk_test (4.1.0) brakeman (>= 5.0.2) capybara (>= 3.36) @@ -280,7 +280,7 @@ GEM method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0820) + mime-types-data (3.2024.0903) mini_mime (1.1.5) minitest (5.25.1) msgpack (1.7.2) @@ -596,8 +596,6 @@ GEM redis-client (>= 0.22.0) redis-client (0.22.2) connection_pool - redis-namespace (1.11.0) - redis (>= 4) regexp_parser (2.9.2) reline (0.5.10) io-console (~> 0.5) @@ -696,10 +694,12 @@ GEM shoulda-context (2.0.0) shoulda-matchers (4.5.1) activesupport (>= 4.2.0) - sidekiq (6.5.5) - connection_pool (>= 2.2.2) - rack (~> 2.0) - redis (>= 4.5.0) + 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) @@ -747,7 +747,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.1) + webrick (1.8.2) websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) diff --git a/app/models/zendesk/zendesk_tickets.rb b/app/models/zendesk/zendesk_tickets.rb index ac5b6f8b..2eb32328 100644 --- a/app/models/zendesk/zendesk_tickets.rb +++ b/app/models/zendesk/zendesk_tickets.rb @@ -12,7 +12,7 @@ def raise_ticket(ticket_to_raise) ticket_options.merge!(custom_fields: ticket_to_raise.custom_fields) if ticket_to_raise.respond_to?(:custom_fields) ticket_options.merge!(ticket_form_id: ticket_to_raise.class::TICKET_FORM_ID) if ticket_to_raise.class.const_defined?(:TICKET_FORM_ID) - ZendeskTicketWorker.perform_async(ticket_options.stringify_keys) + ZendeskTicketJob.perform_async(ticket_options.stringify_keys) end end end diff --git a/app/workers/zendesk_ticket_worker.rb b/app/sidekiq/zendesk_ticket_job.rb similarity index 82% rename from app/workers/zendesk_ticket_worker.rb rename to app/sidekiq/zendesk_ticket_job.rb index 91d1f112..320abf7f 100644 --- a/app/workers/zendesk_ticket_worker.rb +++ b/app/sidekiq/zendesk_ticket_job.rb @@ -1,5 +1,5 @@ -class ZendeskTicketWorker - include Sidekiq::Worker +class ZendeskTicketJob + include Sidekiq::Job sidekiq_retry_in do |exception| case exception @@ -27,3 +27,5 @@ def create_ticket(ticket_options) class TicketNameTooLong < StandardError; end end + +ZendeskTicketWorker = ZendeskTicketJob ## TODO: Remove once queued jobs at the time of the upgrade are complete \ No newline at end of file diff --git a/docs/zendesk-routing.md b/docs/zendesk-routing.md index 3b6cfe4c..566637a1 100644 --- a/docs/zendesk-routing.md +++ b/docs/zendesk-routing.md @@ -3,9 +3,9 @@ ## How tickets are published to Zendesk Support app uses Support API as a client to communicate with Zendesk by calling the [`/support-tickets` endpoint](https://github.com/alphagov/support-api/blob/c0b6ca3587f6673c9512573deeecd66a2aaa0d98/app/controllers/support_tickets_controller.rb). `Services.support_api` is [instantiated in `app/lib/services.rb`](app/lib/services.rb). -The endpoint is exposed via gds_api_adapters gem's [`.raise_support_ticket` method](https://github.com/alphagov/gds-api-adapters/blob/9aabf9d/lib/gds_api/support_api.rb#L25-L39), which is [invoked by the `ZendeskTicketWorker`](https://github.com/alphagov/support/blob/a57843ea587a296a90958b97e5b07baf194c5bf1/app/workers/zendesk_ticket_worker.rb#L27). +The endpoint is exposed via gds_api_adapters gem's [`.raise_support_ticket` method](https://github.com/alphagov/gds-api-adapters/blob/9aabf9d/lib/gds_api/support_api.rb#L25-L39), which is [invoked by the `ZendeskTicketJob`](https://github.com/alphagov/support/blob/a57843ea587a296a90958b97e5b07baf194c5bf1/app/workers/zendesk_ticket_worker.rb#L27). -The `ZendeskTicketWorker` is [created by the `ZendeskTickets` class](https://github.com/alphagov/support/blob/fdf8968f84231f2365207215e40cbaccad2fa6a1/app/models/zendesk/zendesk_tickets.rb#L15), which has a `raise_ticket` method that takes an object of type [`Zendesk::ZendeskTicket`](https://github.com/alphagov/support/blob/37fa7b05ec92511361b2a5e85f2c9f1a1bb3fb51/app/models/zendesk/zendesk_ticket.rb#L6) (or any child class thereof). `ZendeskTickets` is [instantiated in the `RequestsController`](https://github.com/alphagov/support/blob/564e53dc8a3d7a679b0c7f3ff52b91b3dd12e56d/app/controllers/requests_controller.rb#L36) on submission of one of the [live Support forms](https://support.publishing.service.gov.uk/) (one of the forms in the "User access", "Content request", "Technical support", "Campaigns", "Feedback for tools in Beta", "Topic taxonomy requests" or "Other requests" groups). The resulting ticket is tagged as per the `tag` method in whichever `Zendesk::ZendeskTicket` subclass it is, e.g. [`content_amend` tag for the `ContentChangeRequestTicket`](https://github.com/alphagov/support/blob/bcd9984967f70e5338b21455debb3ecd72684de3/app/models/zendesk/ticket/content_change_request_ticket.rb#L10-L12) as well as the default `govt_form` tag [present on the parent class](https://github.com/alphagov/support/blob/37fa7b05ec92511361b2a5e85f2c9f1a1bb3fb51/app/models/zendesk/zendesk_ticket.rb#L50-L52). +The `ZendeskTicketJob` is [created by the `ZendeskTickets` class](https://github.com/alphagov/support/blob/fdf8968f84231f2365207215e40cbaccad2fa6a1/app/models/zendesk/zendesk_tickets.rb#L15), which has a `raise_ticket` method that takes an object of type [`Zendesk::ZendeskTicket`](https://github.com/alphagov/support/blob/37fa7b05ec92511361b2a5e85f2c9f1a1bb3fb51/app/models/zendesk/zendesk_ticket.rb#L6) (or any child class thereof). `ZendeskTickets` is [instantiated in the `RequestsController`](https://github.com/alphagov/support/blob/564e53dc8a3d7a679b0c7f3ff52b91b3dd12e56d/app/controllers/requests_controller.rb#L36) on submission of one of the [live Support forms](https://support.publishing.service.gov.uk/) (one of the forms in the "User access", "Content request", "Technical support", "Campaigns", "Feedback for tools in Beta", "Topic taxonomy requests" or "Other requests" groups). The resulting ticket is tagged as per the `tag` method in whichever `Zendesk::ZendeskTicket` subclass it is, e.g. [`content_amend` tag for the `ContentChangeRequestTicket`](https://github.com/alphagov/support/blob/bcd9984967f70e5338b21455debb3ecd72684de3/app/models/zendesk/ticket/content_change_request_ticket.rb#L10-L12) as well as the default `govt_form` tag [present on the parent class](https://github.com/alphagov/support/blob/37fa7b05ec92511361b2a5e85f2c9f1a1bb3fb51/app/models/zendesk/zendesk_ticket.rb#L50-L52). ## How Zendesk routes tickets diff --git a/spec/models/zendesk/zendesk_tickets_spec.rb b/spec/models/zendesk/zendesk_tickets_spec.rb index 2098df90..5d499823 100644 --- a/spec/models/zendesk/zendesk_tickets_spec.rb +++ b/spec/models/zendesk/zendesk_tickets_spec.rb @@ -14,13 +14,13 @@ describe "#raise_ticket" do before do - allow(ZendeskTicketWorker).to receive(:perform_async) + allow(ZendeskTicketJob).to receive(:perform_async) end - it "calls ZendeskTicketWorker with correct arguments" do + it "calls ZendeskTicketJob with correct arguments" do described_class.new.raise_ticket(ticket_to_raise) - expect(ZendeskTicketWorker).to have_received(:perform_async).with( + expect(ZendeskTicketJob).to have_received(:perform_async).with( "subject" => "Important matter", "priority" => "normal", "requester" => { "locale_id" => 1, "email" => "ab@c.com", "name" => "Harry Potter" }, @@ -30,7 +30,7 @@ ) end - it "calls ZendeskTicketWorker with custom_fields if they are defined in the child class" do + it "calls ZendeskTicketJob with custom_fields if they are defined in the child class" do ticket_with_custom_fields = instance_double( Zendesk::Ticket::ContentChangeRequestTicket, base_ticket_attr.merge(custom_fields: @@ -40,7 +40,7 @@ described_class.new.raise_ticket(ticket_with_custom_fields) - expect(ZendeskTicketWorker).to have_received(:perform_async).with( + expect(ZendeskTicketJob).to have_received(:perform_async).with( hash_including( "custom_fields" => [ { "id" => 1_900_000_744_991, "value" => "2023-08-01" }, @@ -50,7 +50,7 @@ ) end - it "calls ZendeskTicketWorker with ticket_form_id if the constant is defined in the child class" do + it "calls ZendeskTicketJob with ticket_form_id if the constant is defined in the child class" do ticket_with_form_id = instance_double( Zendesk::Ticket::ContentChangeRequestTicket, base_ticket_attr, @@ -60,7 +60,7 @@ described_class.new.raise_ticket(ticket_with_form_id) - expect(ZendeskTicketWorker).to have_received(:perform_async).with( + expect(ZendeskTicketJob).to have_received(:perform_async).with( hash_including( "ticket_form_id" => 123, ), diff --git a/spec/workers/zendesk_ticket_worker_spec.rb b/spec/sidekiq/zendesk_ticket_job_spec.rb similarity index 70% rename from spec/workers/zendesk_ticket_worker_spec.rb rename to spec/sidekiq/zendesk_ticket_job_spec.rb index 957e2882..9d902f44 100644 --- a/spec/workers/zendesk_ticket_worker_spec.rb +++ b/spec/sidekiq/zendesk_ticket_job_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" require "gds_api/test_helpers/support_api" -describe ZendeskTicketWorker do +describe ZendeskTicketJob do it "creates a ticket successfully" do stub = stub_support_api_valid_raise_support_ticket("some" => "options", "requester" => { "email" => "a@b.com" }, "comment" => nil) - ZendeskTicketWorker.new.perform("some" => "options", "requester" => { "email" => "a@b.com" }, "comment" => nil) + ZendeskTicketJob.new.perform("some" => "options", "requester" => { "email" => "a@b.com" }, "comment" => nil) expect(stub).to have_been_made end @@ -14,8 +14,8 @@ stub = stub_support_api_valid_raise_support_ticket("some" => "options", "requester" => { "email" => "a@b.com", "name" => name }) expect { - ZendeskTicketWorker.new.perform("some" => "options", "requester" => { "email" => "a@b.com", "name" => name }) - }.to raise_error(ZendeskTicketWorker::TicketNameTooLong) + ZendeskTicketJob.new.perform("some" => "options", "requester" => { "email" => "a@b.com", "name" => name }) + }.to raise_error(ZendeskTicketJob::TicketNameTooLong) expect(stub).to_not have_been_made end @@ -25,7 +25,7 @@ ) expect { - ZendeskTicketWorker.new.perform( + ZendeskTicketJob.new.perform( "requester" => { "email" => "invalid-email" }, ) }.to raise_error(GdsApi::HTTPUnprocessableEntity)