我試着推遲工作,生產工作(使用Windows,Rails的 4.2.5,如ActiveRecord的ORM我)在我的Gemfile我添加以下內容:Ruby on Rails的活動記錄延遲工作在生產環境中運行
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)
請參閱本評論:http://stackoverflow.com/questions/6994479/initialize-the-delayed-jobs-gem-by-star ting-the-workers-on-application-start – Richard