简体   繁体   中英

How can I automate resque workers to update their code when I push my app to heroku?

The problem is:

When I make changes on the code performed by the workers, the running workers on heroku still executes with the previous after I pushed a new code.

Then I have to manually stop and start again resque. But its wrong, I guess, because the worker could be performing some job and must have to wait it until fininhes to be unregistered.

This is my resque.rake

require 'resque'
require "resque/tasks"

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*' if ENV['QUEUE'].blank?

  Resque::Worker.all.each {|w| w.unregister_worker}
  Resque.after_fork do |job| 
    ActiveRecord::Base.establish_connection
  end
end

task "resque:clean_workers" => :environment do
  Resque::Worker.all.each {|w| w.unregister_worker}
end

desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

I would like to know if when I push my app to heroku, the worker could be updated with the new code. How could it be done?

Thanks!!

Heroku restarts all your processes on deploy as a platform feature -- except for one-off processes spawned via heroku run .

Add the worker process type to your Procfile :

worker: bundle exec rake resque:work QUEUE=*

Push, and then tell Heroku to run your worker:

$ heroku ps:scale worker=1

Heroku will now ensure that you have a single worker dyno running at all times. It'll restart it automatically when your app restarts (eg after a push, a heroku restart , a rollback ), or if your worker dies somehow, or if the host it's on fails. Heroku will even gracefully shut down and restart your worker process on a new host every day or so just for good measure, purging temp files, putting a cap on any memory leaks, and rebalancing load around the dyno grid.

This is the behavior you want if you're running background jobs 24x7 in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM