Commit dfb19b64 authored by charlie ablett's avatar charlie ablett

Merge branch 'fix-default-retries-for-mailers' into 'master'

Set default retries for mailers to 3

See merge request gitlab-org/gitlab!62814
parents f71b4946 d1b9c810
# frozen_string_literal: true
class ActiveJob::QueueAdapters::SidekiqAdapter
# With Sidekiq 6, we can do something like:
# class ActionMailer::MailDeliveryJob
# sidekiq_options retry: 3
# end
#
# See https://gitlab.com/gitlab-org/gitlab/-/issues/329430
raise "Update this monkey patch: #{__FILE__}" unless Sidekiq::VERSION == '5.2.9'
def enqueue(job) #:nodoc:
# Sidekiq::Client does not support symbols as keys
job.provider_job_id = Sidekiq::Client.push \
"class" => JobWrapper,
"wrapped" => job.class.to_s,
"queue" => job.queue_name,
"args" => [job.serialize],
"retry" => retry_for(job)
end
def enqueue_at(job, timestamp) #:nodoc:
job.provider_job_id = Sidekiq::Client.push \
"class" => JobWrapper,
"wrapped" => job.class.to_s,
"queue" => job.queue_name,
"args" => [job.serialize],
"at" => timestamp,
"retry" => retry_for(job)
end
private
def retry_for(job)
if job.queue_name == 'mailers'
3
else
true
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Mailer retries' do
# We need to ensure that this runs through Sidekiq to take
# advantage of the middleware. There is a Rails bug that means we
# have to do some extra steps to make this happen:
# https://github.com/rails/rails/issues/37270#issuecomment-553927324
around do |example|
descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
descendants.each(&:disable_test_adapter)
ActiveJob::Base.queue_adapter = :sidekiq
example.run
descendants.each { |a| a.queue_adapter = :test }
end
it 'sets retries for mailers to 3' do
DeviseMailer.user_admin_approval(create(:user)).deliver_later
expect(Sidekiq::Queues['mailers'].first).to include('retry' => 3)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment