在我的 Rails 应用程序 (4.2.4) 中,我一直在尝试让异步邮件发送工作。
我安装了 delay_job 作为我的队列适配器,并在几个地方将它设置为适配器:config/application.rb、config/environments/{development,production}.rb 和 config/initializers/active_job.rb。
安装:
我将此添加到我的 Gemfile 中:
gem 'delayed_job_active_record'
Run Code Online (Sandbox Code Playgroud)
然后,我运行了以下命令:
$ bundle install
$ rails generate delayed_job:active_record
$ rake db:migrate
$ bin/delayed_job start
Run Code Online (Sandbox Code Playgroud)
在 config/application.rb、config/environments/production.rb、config/environments/development.rb 中:
config.active_job.queue_adapter = :delayed_job
Run Code Online (Sandbox Code Playgroud)
在 config/initializers/active_job.rb 中(在上述方法不起作用时添加):
ActiveJob::Base.queue_adapter = :delayed_job
Run Code Online (Sandbox Code Playgroud)
我还为 delay_job 运行了 ActiveRecord 迁移,并在运行我的服务器之前启动了 bin/delayed_job。
话虽如此,任何时候我尝试:
UserMailer.welcome_email(@user).deliver_later(wait: 1.minutes)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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'
Run Code Online (Sandbox Code Playgroud)
我的印象是 delay_job 是一个排队后端......我错过了什么吗?
编辑:
我也不能让 sucker_punch 工作。在捆绑器中安装吸盘冲床时,并使用:
config.active_job.queue_adapter = …Run Code Online (Sandbox Code Playgroud)