Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Delayed Jobs with Capistrano and Rails 4

I am trying to get Capistrano to start/stop Delayed Jobs with a Rails 4 application. I followed the instructions here, but it says Rails 3. This is how its configured now:

deploy.rb:

require 'delayed/recipes'
after "deploy:start", "delayed_job:start" 
after "deploy:stop", "delayed_job:stop" 
after "deploy:restart", "delayed_job:stop","delayed_job:start"

When I try to deploy I get the following error after it tries to execute RAILS_ENV=production script/delayed_job stop

sh: script/delayed_job: not found
like image 469
Tom Rossi Avatar asked Sep 12 '13 15:09

Tom Rossi


3 Answers

Found the workaround (set :delayed_job_command, "bin/delayed_job") and hope this helps someone else!

deploy.rb:

require 'delayed/recipes'
set :delayed_job_command, "bin/delayed_job"
after "deploy:start", "delayed_job:start"
after "deploy:stop", "delayed_job:stop"
after "deploy:restart", "delayed_job:stop","delayed_job:start"
like image 145
Tom Rossi Avatar answered Oct 26 '22 13:10

Tom Rossi


The accepted answer did not work for me either. I did the following

deploy.rb

def rails_env
  fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
end

execute "cd #{current_path};#{rails_env} bin/delayed_job restart"
like image 43
Dan Herman Avatar answered Oct 26 '22 13:10

Dan Herman


For me this didn't work. My production environment consists of ubuntu 12.04, rails 4, rbenv ruby 2, and for deployment capistrano 3. After messing around a lot with every applicable solution I've come up with this line in my deploy.rb in the restart task.

execute :ruby, "/var/www/app/current/bin/delayed_job restart"

so simple and yet it took me 2 days to come up with it. At my setup I had to manually put bin/delayed_job in place.

Hope someone else find this helpful.

like image 23
user2681178 Avatar answered Oct 26 '22 14:10

user2681178