【问题标题】:rails delayed jobs with "whenever" and "delayed_job_active_record"使用“whenever”和“delayed_job_active_record”来延迟作业
【发布时间】:2016-12-21 09:47:00
【问题描述】:

我从来没有做过延迟的工作,第一次尝试。

我使用每当delayed_job_active_record。每当我按照whenever 的说明进行操作时,就像

gem 'whenever', :require => false
command: wheneverize .

并添加了 schedule.rb

every 2.minutes do
  runner "Page.save_daily_detail"  #Page is name of model, and save_daily_detail put some entries in database
end

whenever --update-crontab

对于delayed_job_active_record

gem 'delayed_job_active_record'

命令:

rails generate delayed_job:active_record
rake db:migrate

也在 application.rb 中

config.active_job.queue_adapter = :delayed_job

当我开始工作时

bundle exec rake jobs:work

它说工作开始但什么也不做。 我在这里错过了什么?

【问题讨论】:

  • 我不明白在你的情况下 crontab 和 delay_job 是如何相互关联的
  • 我想知道同样的事情,如何将它们相互链接
  • 你想构建什么功能?

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


【解决方案1】:

您错过了重新启动 crontab。

whenever --update-crontab <xyz_anyname> --set 'environment=production' #update crontab by passing environment
service crond restart # to restart crontab to reflect changes in Linux system

仅在 linux 上回答有效

在 schedule.rb 中添加这一行

ENV['RAILS_ENV'] = "#{@pre_set_variables[:environment]}"

在本地和生产中相应地更新 crontab 传递环境变量。

【讨论】:

  • 实际上我注意到使用“whenever --update-crontab”它为生产模式创建了cronjob,所以我通过设置环境在开发模式下创建了它,它现在在本地工作。但不能在服务器上工作(处于开发模式)
猜你喜欢
  • 2015-12-18
  • 2016-03-29
  • 2014-09-12
  • 2011-12-14
  • 2022-11-10
  • 2023-04-08
  • 1970-01-01
  • 2013-06-10
  • 2013-09-17
相关资源
最近更新 更多