Sidekiq 作业正在排队,但未得到处理。所有作业都卡在排队中
Sidekiq jobs are getting Enqueued but it's not getting processed. All Jobs are stuck in Enqueued
我正在尝试使用 sidekiq
发送电子邮件,但它不起作用。这是我用 ActiveJob
设置 sidekiq
的方法
宝石文件
gem 'sidekiq'
然后我运行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
用户控制器
def create
...
if @user.save
UserMailer.activation_needed_email(@user).deliver_later # this is were i am sending email.
end
...
end
Rails 服务器日志
[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>>]}
根据上面的日志文件,ActiveJob 已将作业入队,但它使用的是 deliver_now
而不是 deliver_later
。
我的邮箱中没有收到任何电子邮件。当我访问 localhost:3000/sidekiq
时,我可以看到作业已排队但未处理。我如何处理排队中的卡住作业?
更新:
我通过从 application.rb
中删除以下行来解决问题
config.active_job.queue_name_prefix = Rails.env
看起来 sidekiq 与队列名称混淆了。
你需要告诉sidekiq要处理哪些队列。默认情况下,一些框架有自己的队列名称。
创建一个 sidekiq 配置文件(例如 config/sidekiq.yml
)并定义它应该使用的队列
---
: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
然后启动sidekiq配置:sidekiq -C config/sidekiq.yml
我通过从 application.rb
中删除以下行来解决问题
config.active_job.queue_name_prefix = Rails.env
然后通过 sidekiq -q mailers
启动 sidekiq
看起来 sidekiq 与队列名称混淆了。
我正在尝试使用 sidekiq
发送电子邮件,但它不起作用。这是我用 ActiveJob
sidekiq
的方法
宝石文件
gem 'sidekiq'
然后我运行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
用户控制器
def create
...
if @user.save
UserMailer.activation_needed_email(@user).deliver_later # this is were i am sending email.
end
...
end
Rails 服务器日志
[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>>]}
根据上面的日志文件,ActiveJob 已将作业入队,但它使用的是 deliver_now
而不是 deliver_later
。
我的邮箱中没有收到任何电子邮件。当我访问 localhost:3000/sidekiq
时,我可以看到作业已排队但未处理。我如何处理排队中的卡住作业?
更新:
我通过从 application.rb
config.active_job.queue_name_prefix = Rails.env
看起来 sidekiq 与队列名称混淆了。
你需要告诉sidekiq要处理哪些队列。默认情况下,一些框架有自己的队列名称。
创建一个 sidekiq 配置文件(例如 config/sidekiq.yml
)并定义它应该使用的队列
---
: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
然后启动sidekiq配置:sidekiq -C config/sidekiq.yml
我通过从 application.rb
config.active_job.queue_name_prefix = Rails.env
然后通过 sidekiq -q mailers
看起来 sidekiq 与队列名称混淆了。