9z0b3t1c / capistrano-resque

Capistrano integration for Resque
MIT License
223 stars 144 forks source link

Example usage with capistrano v3.1? #73

Closed jfrux closed 10 years ago

jfrux commented 10 years ago

Anyone have a gist or something showing examples of usage with capistrano 3? ' Here is my snippet from deploy.rb

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join("tmp/restart.txt")
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      within release_path do
      end
    end
  end

  after :finishing, 'deploy:cleanup'
  after :restart, 'resque:restart'
end

But I don't see any output saying it's executing the workers.

jfrux commented 10 years ago

Well, I've made it a bit further. I'll keep you posted.

jfrux commented 10 years ago

Okay so now it just hangs at this output:

INFO Starting 2 worker(s) with QUEUE: *
DEBUG [c36a53e3] Running /usr/bin/env if test ! -d /home/getmycme/public_html/current; then echo "Directory does not exist '/home/getmycme/public_html/current'" 1>&2; false; fi on 10.97.106.134
DEBUG [c36a53e3] Command: if test ! -d /home/getmycme/public_html/current; then echo "Directory does not exist '/home/getmycme/public_html/current'" 1>&2; false; fi
DEBUG [9d5df1e7] Running /usr/bin/env if test ! -d /home/getmycme/public_html/current; then echo "Directory does not exist '/home/getmycme/public_html/current'" 1>&2; false; fi on 10.97.106.134
DEBUG [9d5df1e7] Command: if test ! -d /home/getmycme/public_html/current; then echo "Directory does not exist '/home/getmycme/public_html/current'" 1>&2; false; fi

and if I run it directly on the server:

$ cd /home/getmycme/public_html/current && RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=1.9.3-p448 /usr/local/rbenv/bin/rbenv exec bundle exec rake RAILS_ENV=production QUEUE="imports_queue" PIDFILE=./tmp/pids/resque_work_1.pid BACKGROUND=yes VERBOSE=1 INTERVAL=5 environment resque:work
$ rake aborted!
No such file or directory - ./tmp/pids/resque_work_1.pid
/home/getmycme/public_html/shared/bundle/ruby/1.9.1/gems/resque-1.25.1/lib/resque/tasks.rb:36:in `initialize'
/home/getmycme/public_html/shared/bundle/ruby/1.9.1/gems/resque-1.25.1/lib/resque/tasks.rb:36:in `open'
/home/getmycme/public_html/shared/bundle/ruby/1.9.1/gems/resque-1.25.1/lib/resque/tasks.rb:36:in `block (2 levels) in <top (required)>'
Tasks: TOP => resque:work
(See full trace by running task with --trace)
jfrux commented 10 years ago

Ya so, I think I need some help with this... just tested it on 1.9.3-p448 and 2.0.0-p353 and neither will get past this step.

Kind of at a loss...

dmarkow commented 10 years ago

Just to confirm, is this a 3.1-specific problem (i.e. it worked fine on 3.0?)

I didn't realize 3.1 dropped, I'll take a look at it when I have a few minutes.

dmarkow commented 10 years ago

Try the current master branch. We were using some threading code to start multiple instances at once, but it seems to be incompatible with SSHKit 1.3.0 (which Capistrano 3.1 uses). For the time being, I've removed threading for the Cap 3.x code.

cgallemore commented 10 years ago

I'm seeing this exact issue in my current project. We are using Cap 3.1 and I saw the same issues that was originally reported. When I run the cap command it just hangs and then we I ssh in and run it manually I get the same error:

No such file or directory - ./tmp/pids/resque_work_1.pid /var/www/providermatch/shared/bundle/ruby/2.0.0/gems/resque-1.25.1/lib/resque/tasks.rb:36:in initialize' /var/www/providermatch/shared/bundle/ruby/2.0.0/gems/resque-1.25.1/lib/resque/tasks.rb:36:inopen' /var/www/providermatch/shared/bundle/ruby/2.0.0/gems/resque-1.25.1/lib/resque/tasks.rb:36:in `block (2 levels) in <top (required)>'

Was this confirmed that removing the threading fixed the issue?

dmarkow commented 10 years ago

@cgallemore You say you have the same problem outside of Capistrano? If so, I don't think it has anything to do with threading.

It might be that Resque doesn't like relative file paths for the PID, can you test it with a full path to a PID file (rather than ./tmp/pids/resque_work_1.pid) and let me know if it works? If so, I'll update the resque tasks to use a full path instead of a relative one.

cgallemore commented 10 years ago

Ok, I tried a full path and got the same issue. Trying one more thing, I removed the pids directory from the file and just used ./tmp/resque_work_1.pid and that worked as expected. Looks like it's just simply an issue of not having the pids directory in the tmp folder, I kind of assumed that Cap would create that if it didn't exist. I'm a Cap noob though, so that assumption could totally be false.

dmarkow commented 10 years ago

Ah, that makes sense. It's fairly common on a Rails project to have a tmp/pids folder already in place, but we shouldn't assume without checking. At the very least I'll add a directory check so Capistrano will complain if the folder is missing. Thanks!

cgallemore commented 10 years ago

Cool, thanks