views:

72

answers:

3

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 to 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??

A: 

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)

Zepplock
i have added this line on my delayed_job.rb file in config/initializers. And started server with ruby script/server -e production for production. But it's not starting my delayed_job server.
krunal shah
+1  A: 

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"
Tanel Suurhans
i have already set up that thing with capistrano but now i want to start delayed_job when i will start my rails application server or apache.
krunal shah
A: 

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:

[http://stackoverflow.com/questions/1226302/how-to-monitor-delayed-job-with-monit][2]

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

Geoff Lanotte