我正在尝试延迟工作以进行生产(使用Windows,Rails 4.2.5,ActiveRecord作为我的ORM)在我的gemfile中,我添加以下内容:
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'daemons'
在开发中使用延迟作业我在cmd中键入它。
rake jobs:work
它的工作正常。要在生产中使用,我添加bin / delayed_job.rb, 在我的初始化中,我添加了delayed_job.rb。我的内心 initialiazers / delayed_job.rb
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 3
Delayed::Worker.max_run_time = 5.minutes
Delayed::Worker.read_ahead = 10
Delayed::Worker.default_queue_name = 'default'
Delayed::Worker.delay_jobs = !Rails.env.test?
Delayed::Worker.raise_signal_exceptions = :term
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
if Rails.env.production?
system 'RAILS_ENV=production bin/delayed_job start'
system 'RAILS_ENV=production bin/delayed_job stop'
end
当我在生产中运行程序时,DelayedJob只是在数据库中创建记录,但它没有运行。我的delayed_job.log
中没有记录日志这是更新的代码。
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 3
Delayed::Worker.max_run_time = 5.minutes
Delayed::Worker.read_ahead = 10
Delayed::Worker.default_queue_name = 'default'
Delayed::Worker.delay_jobs = !Rails.env.test?
Delayed::Worker.raise_signal_exceptions = :term
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
if Rails.env.production?
system "RAILS_ENV=production #{Rails.root}/bin/delayed_job start"
system "RAILS_ENV=production #{Rails.root}/bin/delayed_job start"
end
我只是将Rails_env =开发更改为生产并添加了Rails.root,Iforgot说我使用Jruby 9.0.4.0(2.2.2)
答案 0 :(得分:0)
我认为你错过了绝对的道路。 你也应该只有一个delayed_job开始调用。 如果你想要两个delayed_job实例,你应该传递一些worker(更新我的例子以显示) 尝试将其更改为:
if Rails.env.production?
system "RAILS_ENV=development #{Rails.root}/bin/delayed_job start --number_of_workers=2"
end
在更改之后,并在生产中重新启动,运行:
$ ps -ef | grep delayed_job
......应该显示:
$ your_user 4242 1 0 10:12 ? 00:00:00 delayed_job