Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Set retry_on options for some jobs

Oliver Günther27268568f8ec
diff --git a/app/workers/mailer_job.rb b/app/workers/mailer_job.rb
index 4ac6e6411b5..f638cb16288 100644
--- a/app/workers/mailer_job.rb
+++ b/app/workers/mailer_job.rb
@@ -45,6 +45,11 @@
class MailerJob < ApplicationJob
queue_as { ActionMailer::Base.deliver_later_queue_name }
+ # Retry mailing jobs three times with exponential backoff
+ retry_on StandardError, wait: :exponentially_longer, attempts: 3
+
+ # If exception is handled in mail handler
+ # retry_on will be ignored
rescue_from StandardError, with: :handle_exception_with_mailer_class
def perform(mailer, mail_method, delivery_method, *args)
diff --git a/modules/webhooks/app/workers/represented_webhook_job.rb b/modules/webhooks/app/workers/represented_webhook_job.rb
index bfd378b19f1..528d0b790e9 100644
--- a/modules/webhooks/app/workers/represented_webhook_job.rb
+++ b/modules/webhooks/app/workers/represented_webhook_job.rb
@@ -51,6 +51,9 @@ class RepresentedWebhookJob < WebhookJob
begin
response = RestClient.post webhook.url, request_body, headers
+ rescue RestClient::RequestTimeout => e
+ response = e.response
+ exception = e
rescue RestClient::Exception => e
response = e.response
exception = e
@@ -69,6 +72,12 @@ class RepresentedWebhookJob < WebhookJob
response_headers: response.try(:headers),
response_body: response.try(:to_s) || exception.try(:message)
)
+
+ # We want to re-raise timeout exceptions
+ # but log the request beforehand
+ if exception&.is_a?(RestClient::RequestTimeout)
+ raise exception
+ end
end
def accepted_in_project?
diff --git a/modules/webhooks/app/workers/webhook_job.rb b/modules/webhooks/app/workers/webhook_job.rb
index c2e16ba7af3..e4a3e617fd7 100644
--- a/modules/webhooks/app/workers/webhook_job.rb
+++ b/modules/webhooks/app/workers/webhook_job.rb
@@ -30,6 +30,13 @@
class WebhookJob < ApplicationJob
attr_reader :webhook_id, :event_name
+ # Retry webhook jobs three times with exponential backoff
+ # in case of timeouts
+ retry_on Timeout::Error,
+ RestClient::RequestTimeout,
+ wait: :exponentially_longer,
+ attempts: 3
+
def perform(webhook_id, event_name)
@webhook_id = webhook_id
@event_name = event_name