README.markdown in resque-cleaner-0.0.2 vs README.markdown in resque-cleaner-0.1.0

- old
+ new

@@ -6,25 +6,26 @@ Description ----------- ResqueCleaner is a [Resque](https://github.com/defunkt/resque) plugin which -helps you to deal with failed jobs of Resque by: +helps you to deal with failed jobs on Resque by: * Showing stats of failed jobs * Retrying failed jobs * Removing failed jobs * Filtering failed jobs -Although ResqueCleaner hasn't integrated with Resque's web-based interface yet, +Although ResqueCleaner has not integrated with Resque's web-based interface yet, it is pretty easy to use on irb(console). Installation ------------ Install as a gem: + $ gem install resque-cleaner Usage ----- @@ -51,13 +52,15 @@ HorribleJob: 7 total: 10 => {'BadJob' => 3, ...} You can get the ones filtered with a block: it targets only jobs which the block -evaluetes true. e.g. Show stats only of jobs entried with some arguments. +evaluetes true. - > cleaner.stats_by_date{|job| job["payload"]["args"].size > 0} +e.g. Show stats only of jobs entried with some arguments: + + > cleaner.stats_by_date {|j| j["payload"]["args"].size > 0} 2009/03/13: 3 2009/11/13: 7 2010/08/13: 11 total: 22 => {'2009/03/10' => 3, ...} @@ -67,32 +70,36 @@ You can retry all failed jobs with this method. > cleaner.requeue Of course, you can filter jobs with a block; it requeues only jobs which the -block evaluates true. e.g. Retry only jobs with some arguments. +block evaluates true. - > cleaner.requeue{ |job| job["payload"]["args"].size > 0} +e.g. Retry only jobs with some arguments: + > cleaner.requeue {|j| j["payload"]["args"].size > 0} + The job hash is extended with a module which defines some useful methods. You -can use it in the blcok. e.g. Retry only jobs entried within a day. +can use it in the blcok. +e.g. Retry only jobs entried within a day: + > cleaner.requeue {|j| j.after?(1.day.ago)} e.g. Retry EmailJob entried with arguments within 3 days: - > cleaner.requeue {|j| j["payload"]["args"]>0 && j.after?(3.days.ago) && j.klass?(EmailJob)} + > cleaner.requeue {|j| j.after?(3.days.ago) && j.klass?(EmailJob) && j["payload"]["args"].size>0} -See Helper Methods bellow for more. +See Helper Methods section bellow for more information. NOTE: [1.day.ago](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/time.rb) -is not in standard library. It is equivalent to `Time.now - 60*60*24*3`. +is not in standard library. Using it for making explanation more understandable. It is equivalent to `Time.now - 60*60*24*3`. **Clear Jobs** -You can clear all failed jobs with this method. +You can clear all failed jobs with this method: > cleaner.clear Like you can do with the retry method, the clear metod takes a block. Here are some examples: @@ -107,25 +114,40 @@ => clears all jobs raised RuntimeError and queued :low queue **Retry and Clear Jobs** You can retry(requeue) and clear failed jobs at the same time; just pass true -as an argument. e.g. Retry EmailJob and remove from failed jobs. +as an argument. +e.g. Retry EmailJob and remove from failed jobs: + > cleaner.requeue(true) {|j| j.klass?(EmailJob)} +**Retry with other queue** + +You can requeue failed jobs into other queue. In this way, you can retry failed +jobs without blocking jobs being entried by your service running in the live. + +e.g. Retry failed jobs on :retry queue + + > cleaner.requeue(false, :queue => :retry) + +Don't forget to launch resque worker for the queue. + + % QUEUE=retry rake resque:work + **Select Jobs** You can just select the jobs of course. Here are some examples: > cleaner.select {|j| j["exception"]=="RuntimeError"} > cleaner.select {|j| j.after?(2.days.ago)} > cleaner.select #=> returns all jobs **Helper Methods** -Here is a list of methods a job extended. +Here is a list of methods a failed job ratained through ResqueCleaner has: retried?: returns true if the job has already been retried. requeued?: alias of retried?. before?(time): returns true if the job failed before the time. after?(time): returns true if the job failed after the time. @@ -134,12 +156,11 @@ Failed Job ----------- -I show a sample of failed job here; it might help you when you write a block for -filtering failed jobs. +Here is a sample of failed jobs: {"failed_at": "2009/03/13 00:00:00", "payload": {"args": ["Johnson"], "class": "BadJob"}, "queue": "jobs", "worker": "localhost:7327:jobs,jobs2", @@ -163,19 +184,19 @@ out there. Since ResqueCleaner's filter function is running on your application process but on your Redis, it would not respond ages if you try to deal with all of those jobs. ResqueCleaner supposes recent jobs are more important than old jobs. Therefore -ResqueCleaner deals with **ONLY LAST X(default=1000)** jobs. In that way, you -don't have to worry that your block for filtering might be stuck. You can change -its setting through `limiter` attribute. I will show you how it works with a -sample situation. +ResqueCleaner deals with **ONLY LAST X(default=1000) JOBS**. In this way, you +could avoid slow responses. You can change the number through `limiter` attribute. +Let's see how it works with an follwing example. + **Sample Situation** * Number of failed jobs: 100,000 -Default limiter is 1000 so that it returns 1000 as a count. +Default limiter is 1000 so that the limiter returns 1000 as a count. > cleaner.limiter.count => 1,000 > cleaner.failure.count => 100,000