Skip to content

Commit

Permalink
Rename ZendeskTicketWorker -> ZendeskTicketJob
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AgaDufrat committed Oct 3, 2024
1 parent f94e3b3 commit 9119794
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/models/zendesk/zendesk_tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ZendeskTicketWorker
include Sidekiq::Worker
class ZendeskTicketJob
include Sidekiq::Job

sidekiq_retry_in do |exception|
case exception
Expand Down Expand Up @@ -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

Check failure on line 31 in app/sidekiq/zendesk_ticket_job.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/TrailingEmptyLines: Final newline missing. (https://rubystyle.guide#newline-eof)
4 changes: 2 additions & 2 deletions docs/zendesk-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions spec/models/zendesk/zendesk_tickets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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:
Expand All @@ -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" },
Expand All @@ -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,
Expand All @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -25,7 +25,7 @@
)

expect {
ZendeskTicketWorker.new.perform(
ZendeskTicketJob.new.perform(
"requester" => { "email" => "invalid-email" },
)
}.to raise_error(GdsApi::HTTPUnprocessableEntity)
Expand Down

0 comments on commit 9119794

Please sign in to comment.