ActiveJob 和 Sidekiq 作业陷入队列

uti*_*tiq 5 ruby ruby-on-rails sidekiq rails-activejob

所以我刚刚迁移到 Rails 5.1.4,我试图让 Active Job 工作,但作业只是卡在队列中并且从未被处理。

  • 导轨:5.1.4
  • 红宝石:2.4.3
  • sidekiq:5.0.5
  • 雷迪斯:4.0.1

sidekiq.yml

---
:verbose: true
:concurrency: 5
:timeout: 60
development:
  :concurrency: 25
staging:
  :concurrency: 50
production:
  :concurrency: 5
:queues:
  - default
  - [high_priority, 2]
Run Code Online (Sandbox Code Playgroud)

sidekiq.rb

Sidekiq.configure_server do |config|
  config.redis = {url: ENV['ACTIVE_JOB_URL'], network_timeout: 5}
end

Sidekiq.configure_client do |config|
  config.redis = {url: ENV['ACTIVE_JOB_URL'], network_timeout: 5}
end
Run Code Online (Sandbox Code Playgroud)

以下是我从 Rails 控制台执行任务的方式:

TestJob.perform_later
Run Code Online (Sandbox Code Playgroud)

TestJob.rb内容:

class TestJob < ApplicationJob
  queue_as :default

  def perform(*args)
    Rails.logger.debug "#{self.class.name}: I'm performing my job with arguments: #{args.inspect}"
  end
end
Run Code Online (Sandbox Code Playgroud)

这些作业只是停留在队列中并且从未被处理:

在此输入图像描述

ard*_*igh 4

您是否启动了工作人员,例如在开发中它可能是:

bundle exec sidekiq
Run Code Online (Sandbox Code Playgroud)

如果在生产环境中,如果您已经配置了Procfile ,Heroku 应该为您执行此操作,例如:

web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq
Run Code Online (Sandbox Code Playgroud)

您还可以在开发中使用 Procfile 与foreman一起使用,例如:

foreman start -f Procfile 
Run Code Online (Sandbox Code Playgroud)