NotImplementedError(使用排队后端......)使用delayed_job

时间:2016-05-17 15:20:38

标签: ruby-on-rails queue delayed-job

在我的Rails应用程序(4.2.4)中,我一直试图让异步邮件发送到工作中。

我安装了delayed_job作为我的队列适配器,并在几个地方将其设置为适配器:config / application.rb,config / environments / {development,production} .rb和config / initializers / active_job.rb。

安装:

我将此添加到我的Gemfile:

gem 'delayed_job_active_record'

然后,我运行了以下命令:

$ bundle install
$ rails generate delayed_job:active_record
$ rake db:migrate
$ bin/delayed_job start

在config / application.rb中,config / environments / production.rb,config / environments / development.rb:

config.active_job.queue_adapter = :delayed_job

在config / initializers / active_job.rb中(当上面的内容不起作用时添加):

ActiveJob::Base.queue_adapter = :delayed_job

我还为delayed_job运行了ActiveRecord迁移,并在运行我的服务器之前启动了bin / delayed_job。

有人说,只要我尝试:

UserMailer.welcome_email(@user).deliver_later(wait: 1.minutes)

我收到以下错误:

NotImplementedError (Use a queueing backend to enqueue jobs in the
future. Read more at http://guides.rubyonrails.org/active_job_basics.html):
    app/controllers/user_controller.rb:25:in `create'
    config.ru:25:in `call'

我的印象是delayed_job是一个排队的后端...我错过了什么?

编辑:

我也无法让sucker_punch工作。在捆绑器中安装sucker_punch时,使用:

config.active_job.queue_adapter = :sucker_punch

在config / application.rb中,我得到了相同的错误和堆栈跟踪。

4 个答案:

答案 0 :(得分:2)

即使您使用的适配器能够执行Sidekiq之类的异步作业,即使在开发环境中仍遇到此问题,请确保将Rails.application.config.active_job.queue_adapter设置为:async而不是:inline

# config/environments/development.rb

Rails.application.config.active_job.queue_adapter = :async

答案 1 :(得分:1)

假设您按照列出here列出的所有步骤,我觉得您没有启动delayed_job运行

bin/delayed_job start

还请检查你的运行

rails generate delayed_job:active_record
rake db:migrate

答案 2 :(得分:1)

试试这个:

控制器中的

@user.delay.welcome_email

在您的模型中

def welcome_email
 UserMailer.welcome_email(self).deliver_later(wait: 1.minutes)

end

答案 3 :(得分:0)

弄清楚它是什么:我通常使用单个shell脚本启动我的服务器以及与之关联的所有内容。在这个脚本中,我在后台运行bin/delayed_job start,并在bin/delayed_job start完成之前启动服务器。解决方案是通过在启动脚本的前台运行服务器来确保{<1}}在启动服务器之前完成

感谢大家的帮助!