2016-10-18 91 views
0

我試着推遲工作,生產工作(使用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)

+0

請參閱本評論:http://stackoverflow.com/questions/6994479/initialize-the-delayed-jobs-gem-by-star ting-the-workers-on-application-start – Richard

回答

0

我認爲你缺少的絕對路徑。 您還應該只有一個delayed_job開始呼叫。 如果你想的delayed_job的兩個實例,則應該通過對工人的數量(更新我的例子證明) 嘗試將其更改爲:

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 
+0

我已經添加了Rails.root,但仍然無法正常工作。 –

+0

你可以更新你的問題,看看代碼現在看起來好嗎? – Richard

+0

我在問題中添加我的新代碼 –