I am trying to send email using sidekiq
but it's not working. Here is how i setup sidekiq
with ActiveJob
Gemfile
gem 'sidekiq'
then i run bundle install
.
Application.rb
config.active_job.queue_adapter = :sidekiq
config.active_job.queue_name_prefix = Rails.env
UserMailer.rb
class UserMailer < ApplicationMailer
def activation_needed_email(user)
@user = user
@url = activate_user_url(@user.activation_token)
mail(to: user.email, subject: 'Welcome to My website')
end
end
UsersController
def create
...
if @user.save
UserMailer.activation_needed_email(@user).deliver_later # this is were i am sending email.
end
...
end
Rails Server Log
[ActiveJob] Enqueued ActionMailer::MailDeliveryJob (Job ID: e61df8eb-c6c1-417a-af59-d55fdc13ec98) to Sidekiq(mailers) with arguments: "UserMailer", "activation_needed_email", "deliver_now", {:args=>[#<GlobalID:0x00007fabff6a3c60 @uri=#<URI::GID gid://jobs-in-nepal/User/83c17355-db86-4ca1-b674-a97fde512592>>]}
According to above log file ActiveJob has Enqueued the job, but it's using deliver_now
rather than deliver_later
.
I am not receiving any email in my mailbox. When i visit localhost:3000/sidekiq
then I can see that job is enqueued but job is not processed. How can i process the stuck jobs from enqueued?
UPDATE:
I fixed the problem by deleting following line from application.rb
config.active_job.queue_name_prefix = Rails.env
looks like sidekiq was getting confused with queue name.
I fixed the problem by deleting following line from application.rb
config.active_job.queue_name_prefix = Rails.env
and then starting sidekiq by sidekiq -q mailers
looks like sidekiq was getting confused with queue name.