By admin754635
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.
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!
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.
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:
Install Redis on the droplet using this helpful article : https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
Use foreman/upstart as suggested in the comment above to detail the tasks/servers that you want to run. The procfile is what will be used to run the processes. The following links are helpful for understanding: http://blog.daviddollar.org/2011/05/06/introducing-foreman.html http://railscasts.com/episodes/281-foreman
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
Resque.redis = ENV['REDIS_URL']
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.