r3b00t
r3b00t

Reputation: 7533

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.

Upvotes: 3

Views: 7363

Answers (2)

r3b00t
r3b00t

Reputation: 7533

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.

Upvotes: 7

pdu
pdu

Reputation: 10413

You need to tell sidekiq which queues to process. By default, some frameworks have their own queue names.

Create a sidekiq configuration file (e. g. config/sidekiq.yml) and define the queues that it should use

---
:verbose: false
:concurrency: 2
:max_retries: 3
:timeout: 10

:queues:
  # The default queue for all application jobs that don't have a specific queue.
  - default

  # The default queue for ActionMailer classes.
  - mailers

  # ActionMailbox queues. See `ActionMailbox.queues`.
  - action_mailbox_routing
  - action_mailbox_incineration

  # ActiveStorage queues. See `ActiveStorage.queues`.
  - active_storage_analysis
  - active_storage_purge

Then start sidekiq with the configuration: sidekiq -C config/sidekiq.yml

Upvotes: 3

Related Questions