Question

How do I run resque background tasks on my droplet using foreman, capistrano and nginx?

I have not been able to find any documentation on how to run worker tasks in the background for something like Resque. There is an article for installing Redis on the droplet: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis, and I have a Procfile using Foreman gem in which I have the background tasks, but I can’t figure how to run them on the droplet.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks for pointing me in the right direction. There were still a few issues that I faced in implementing this properly, so I thought I’d help others trying to implement this in their app. I assume that resque has already been implemented in the app locally. I followed these steps for implementing resque on my app hosted on digital ocean:

This is what my Procfile looks like :

worker:  RAILS_ENV=production bundle exec rake resque:work QUEUE='*'
scheduler: RAILS_ENV=production bundle exec rake resque:scheduler
faye: bundle exec rackup private_pub.ru -s thin -E production
  • Make changes in the resque configuration to run the resque server on the app’s production IP: in initializers/resque-web.rb
Resque.redis = ENV['REDIS_URL']
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
  • The following capistrano tasks need to be created to run the servers/tasks mentioned in the Procfile : in config/deploy.rb
task :export do

    on roles(:app) do
      execute [
        "cd #{release_path} &&",
        'export rvmsudo_secure_path=0 && ',
        "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do",
        'rvmsudo',
        'RAILS_ENV=production bundle exec foreman export --app appname --user username -l logfile-path -f ./Procfile upstart /etc/init -c worker=1,scheduler=1,faye=1'
      ].join(' ')
    end
end


task :restart do 
  on roles(:app) do
    execute :sudo, "restart appname"
  end
end
after :publishing, :export
   after :publishing, :restart

This should get the workers going.

The Resque wiki provide a sample cap task to manage Resque processes.

namespace :foreman do
  desc "Start the application services"
  task :start, :roles => :app do
    sudo "start #{application}"
  end

  desc "Stop the application services"
  task :stop, :roles => :app do
    sudo "stop #{application}"
  end

  desc "Restart the application services"
  task :restart, :roles => :app do
    run "sudo start #{application} || sudo restart #{application}"
  end

  desc "Display logs for a certain process - arg example: PROCESS=web-1"
  task :logs, :roles => :app do
    run "cd #{current_path}/log && cat #{ENV["PROCESS"]}.log"
  end

  desc "Export the Procfile to upstart scripts"
  task :export, :roles => :app do
    # 5 resque workers, 1 resque scheduler
    run "cd #{release_path} && rvmsudo bundle exec foreman export upstart /etc/init -a #{application} -u #{user} -l #{shared_path}/log  -f #{release_path}/Procfile.production -c worker=5,scheduler=1"
  end 
end

It builds off this blog post on managing and monitoring a Ruby application with Foreman and Upstart. That should point you in the right direction.