简体   繁体   中英

How to kill resque workers on Heroku?

I am using this guide to setup Resque with Redis http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/

I have it all set up and when I put something it shows up on my resque queue. It is on heroku so then I run

heroku rake resque:work QUEUE=*
(in /app)
Starting the New Relic Agent.
Installed New Relic Browser Monitoring middleware
Connected to NewRelic Service at collector-1.newrelic.com:80
^C
[canceled]

This then completes the job, but now the worker is still there. How do I now delete/kill the worker?

I currently have this 0 of 4 Workers Working I want to make it so that after the tasks in the queue are completed then the worker just deletes itself. How would I go on doing this or is there another heroku terminal command I need to call.

Also do resque workers cost any money on heroku? I just want to make so I can manually trigger tasks in my resque queue. I dont need it to be doing it automatically.

I know this is an old question but you can do it from the console:

$ heroku run console
irb(main):001:0> Resque.working[0].id
=> "09ec127d-bb90-4629-a6f2-bb2610885ab5:62:*"
irb(main):002:0> Resque.working.length
=> 28
irb(main):003:0> Resque.remove_worker("09ec127d-bb90-4629-a6f2-bb2610885ab5:62:*")
=> 0
irb(main):004:0> Resque.working.length
=> 27
irb(main):005:0> 

I haven't tried it yet but there's also a gem for doing this manually , sounds like you want to automate it though.

To integrate with the heroku workers you need to implement a rake task called jobs:work. To get this working with resque you need to add the following task to a rake file(taken from http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/ ):

require 'resque/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'
end

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

To start a single worker on heroku use:

? heroku workers 1

To switch off background workers do:

? heroku workers 0

To use 5 workers do:

? heroku workers 5

Heroku charges you by the second for each worker that you run. If you log into heroku you'll be able to see how much your current number of workers will cost on the resources page for your app.

On the Heroku Cedar Stack this is pretty easy, this is the command to change the number of workers to n you would run this command, and it would kill/create workers to achieve n .

heroku ps:scale worker=n --app your-app-name

See this article at Heroku for more details: https://devcenter.heroku.com/articles/scaling

Have you tried out HireFire ?

Its designed specifically to scale up/down Resque (and Delayed Job) workers on Heroku.

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