开发者

Starting delayed_job at startup with rails

I want to start script/delayed_job start on my production when i will start my rails server. Is there anyway i can do that?

EDIT::

I have added this line 开发者_如何学Cto my config/initializers/delayed_job.rb .

Delayed::Worker.new.start 

But my delayed job server is not starting when i am running my rails applicaiton. Is there any other solution??


I would recommend deploying your app with Capistrano and defining a after:deploy hook to start/restart DJ at every deploy.

I would also recommend using Resque over DelayedJob, as the latter has tendencies to just die without any reason, and usually requires a Monit/God monitoring and restarting it.

namespace :delayed_job do
  desc "Start delayed_job process" 
  task :start, :roles => :app do
    run "cd #{current_path}; script/delayed_job start #{rails_env}" 
  end

  desc "Stop delayed_job process" 
  task :stop, :roles => :app do
    run "cd #{current_path}; script/delayed_job stop #{rails_env}" 
  end

  desc "Restart delayed_job process" 
  task :restart, :roles => :app do
    run "cd #{current_path}; script/delayed_job restart #{rails_env}" 
  end
end

after "deploy:start", "delayed_job:start" 
after "deploy:stop", "delayed_job:stop" 
after "deploy:restart", "delayed_job:restart"


You can setup an init.d file, but I would recommend either monit or god. God is ruby, so it is familiar, but that also means it leaks a bit. If you are going to run God, I recommend a cron job to restart it. This is a VERY good post on configuring monit on your server.

We went the God route, but if we had it to do over again - we would do monit.


You can do

Delayed::Worker.new.start

in your initializers directory (create a new ".rb" file in there and it'll start with your app)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜