Skip to content

Commit

Permalink
Make WebhookWorker WebhookJob
Browse files Browse the repository at this point in the history
Sidekiq Workers are no longer supported by the new version
  • Loading branch information
JonathanHallam committed Sep 26, 2024
1 parent e6851db commit 9b9024f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions app/workers/webhook_worker.rb → app/workers/webhook_job.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,15 +25,15 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/govuk_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
config.data_sync_excluded_exceptions += %w[
Faraday::ServerError
Faraday::ConnectionFailed
RestartWorkerException
RestartJobException
]
end
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9b9024f

Please sign in to comment.