Search code examples
ruby-on-railssidekiqrails-activejob

Sidekiq jobs are getting Enqueued but it's not getting processed. All Jobs are stuck in Enqueued


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?

enter image description here

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.


Solution

  • 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.