Resque manipulations
Yesterday I came to one production project and saw several Resque Failures. And it seems one of them blocked others, so the queue hungs for more than 20 jobs.
When trying to investigate the bug, we added to the queue a lot of unnecessary and repetitive tasks. In that case, just restart the queue - a bad option, because it'll execute all tasks. Also it's impossible to clean, and because there are important tasks that can't be lost and hard for manually adding.
It was decided to remove unnecessary tasks by hands.
Here I come upon the first disappointment - resque web cannot remove just one job, only everything. In documentation and in stack overflow I can't find any answers. Nowhere is information about how to do this from the console manually (maybe I bad googler, but anyway). By digging into the source code I discovered needed commands. So decided to share it, so that if you have to perform similar actions, it'll be easier to you.
First, make sure, that Redis works:
irb(main):> Resque => Resque Client connected to redis://127.0.0.1:6379/0
Nice. Can go forth. After we should take a look on our queues:
irb(main):> Resque.queues => ["orders_processing", "mailers"]
It's just simple Array of strings, so we can't work with it.
Next command was unnecessary for me, but can be helpful for you, if you want to list your workers:
irb(main):> Resque::Worker.all => [#<Worker our_project:9421:*>, #<Worker our_project:22184:*>]
Next command helps you when you want get list of active workers:
irb(main):> Resque::Worker.working => []
In my case all wokers dead =(
If you have queues separating by workers, you probably want to know, which ones belongs to whom:
irb(main):> Resque::Worker.all.first.queues => ["mailers", "orders_processing"]
If you want, you can get list of failures not in Resque-web, but from console, do that:
irb(main):> Resque::Failure.all => ..there is big array of errors..
It's clear about different Resque queues, workers and etc. So how we can get list of jobs for specified queue? As simple as chunky backon!
irb(main):> Resque.peek("mailers") => {"class"=>"Mailer", "args"=>["registered", {"approved"=>false, "created_at"=>"time", "email"=>"email", "id"=>"}]}
By default that command returns just one element. Don't worry, it has two more arguments for list length:
irb(main):> Resque.peek("mailers", 0, 20) => [{"class"=>"Mailer", "args"=>["registered", {"approved"=>false, "created_at"=>"time", "email"=>"email", "id"=>"}]}, {"class"=>"Notifier", "args"=>["thank_you", "second_param"]}]
Now we can see information for separate jobs and it's simple to remove what you want:
irb(main):> Resque::Job.destroy("mailer", "Notifier", ["thank_you"]) => 0
Ooops =( Nothing removed. Reason is not-fully specified params. It should be absolutely total.
irb(main):> Resque::Job.destroy("mailer", "Notifier", ["thank_you", "second_param"]) => 1
Now you can delete bad jobs from Resque. I hope this information will help you if you have to manually fiddle with Resque!












