While upgrading my Rails 6.0 application to Rails 7.0.3, I'm facing the following problem :
Sidekiq is enqueueing all my mailer jobs through the default
queue instead of the mailers
queue like it used to before.
Code related to the same :
in application.rb :
config.active_job.queue_adapter = :sidekiq
My mailer :
class UserMailer < ActionMailer::Base
def staff_welcome(user, password)
@user = user
@password = password
mail(to: user.email, from: "DummyName <#{APP_CONFIG[:notifications_email]}>", reply_to: "#{APP_CONFIG[:outbound_email]}", subject: "Your staff account has been created")
end
And then, inside the controller, i'm calling the mailer as follows :
def create
@user = User.new
@user.attributes = users_params.merge(state: 'active', source: :dummy_source, activity: 1)
set_roles(users_params)
respond_to do |format|
if @user.save
if @user.staff?
UserMailer.staff_welcome(@user, params[:user][:password]).deliver_later
I'm interested in finding out why upon upgrading to Rails 7 is my queue for mailers changing? When i run the server with Rails 6, the mailers get queued via the mailers
queue, but with Rails 7, the queue is default
.
I understand that if i call the mailer from inside an ActiveJob, and inside the controller call the job instead of the mailer directly, I will be able to use syntax like queue_as :mailers
. Is that the correct way to fix this?
I checked the changelog for sidekiq but couldn't find anything related to this? Did they change the default queue when it comes to mailers?
Also, can i set sidekiq_options with the deliver_later
function?
In Rails 6.1, they changed the default queue name.
More info on the change here: https://github.com/rails/rails/pull/40766
In the Sidekiq documentation: https://github.com/sidekiq/sidekiq/wiki/Active-Job#queues