Heroku 上未处理delayed_job 队列
我正在运行带有delayed_job 的Rails 3 应用程序。我遇到的问题是,尽管应用程序正确地将作业添加到队列中,但它们从未被处理。
我的班级
class User < ActiveRecord::Base
after_create :send_welcome_email
private
def send_welcome_email
UserMailer.delay.welcome_email(self)
end
end
通过 Rails 控制台检查,我可以看到队列中有作业。我还可以看到执行这些作业的尝试次数为 0。启动 Heroku 工作线程不会导致作业得到处理。
有什么想法吗?
谢谢!
编辑:尝试按照下面的建议清除作业队列,我运行了rake jobs:clear
并收到了以下错误
rake aborted!
uninitialized constant Rake::DSL
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (requ
ired)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>
'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/app/Rakefile:7:in `<top (required)>'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `<main>'
I'm running a Rails 3 app with delayed_job. The issue I've come across is that though the app is correctly adding jobs to the queue, they are never being processed.
My Class
class User < ActiveRecord::Base
after_create :send_welcome_email
private
def send_welcome_email
UserMailer.delay.welcome_email(self)
end
end
Inspecting things through the Rails console I can see that there are jobs in the queue. I can also see that there have been 0 attempts to perform the jobs. Spinning up a Heroku worker doesn't cause the jobs to be processed.
Any ideas?
Thanks!
Edit: Trying to clear the jobs queue as suggested below I ran rake jobs:clear
and received the following error
rake aborted!
uninitialized constant Rake::DSL
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (requ
ired)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>
'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/app/Rakefile:7:in `<top (required)>'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `<main>'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最终,问题被证明是Rake 0.9.0中的一个bug。由于 Rails 依赖于 Rake,因此在 Rake 发布后运行
bundle install
破坏了我延迟的工作。解决方法是将
gem 'rake', '0.8.7'
添加到您的 gemfile 中。更多详细信息如下...
DHH 的推文: http://twitter.com/dhh/status/71966528744071169
rails_admin 问题跟踪器中的讨论:https://github.com/sferik/rails_admin/issues/428
In the end, the problem turned out to be a bug in Rake 0.9.0. As Rails depends on Rake, running
bundle install
after this release of Rake broke my delayed jobs.The fix is to add
gem 'rake', '0.8.7'
to your gemfile.More details can be found below...
DHH's tweet: http://twitter.com/dhh/status/71966528744071169
Discussion in rails_admin's issue tracker: https://github.com/sferik/rails_admin/issues/428
有两个选项供您使用:
这两个 gem 监视elasted_jobs 队列并自动“雇用”后台工作人员来处理线程:
祝你好运
Two options for you:
These two gems watch delayed_jobs queue and automatically 'hires' background workers to process the thread:
Good luck
您是否在应用程序运行的同一环境中运行delayed_job 守护进程?
尝试使用以下方法手动处理作业:
rake RAILS_ENV=development jobs:work
如果您在生产模式下运行您的应用程序,那么您需要按以下方式启动delayed_job 守护进程:
RAILS_ENV=生产脚本/delayed_job开始
Are you running the delayed_job daemon in the same environment in which the application is running?
Try working the jobs manually using:
rake RAILS_ENV=development jobs:work
If you are running your app in production mode then you need to start delayed_job daemon as:
RAILS_ENV=production script/delayed_job start
这有点遥远,但请确保您在 Heroku 上使用的 Ruby 版本与您在本地计算机上使用的 Ruby 版本相同。由于这个原因,我之前在 Heroku 上遇到了延迟作业的问题。
This is kinda a long shot but make sure you are using the same Ruby version on Heroku as you are on your local machine. I had a problem with delayed jobs on Heroku before because of this.