I think you can do this by viewing the jobs stats (my example is in
Ruby but python should work the same.)
job = beanstalk.reserve
p job.stats
{"releases"=>1, "delay"=>0, "kicks"=>0, "buries"=>0, "id"=>10,
"tube"=>"api-run-requests", "time-left"=>115, "ttr"=>120,
"pri"=>65536, "timeouts"=>1, "age"=>143, "state"=>"reserved"}
>From the stats you can view releases and timeouts. If you are
explicitly doing a release you can just check the count of
job['releases'] and if it is less than 3 try it, if it is more than 3
just delete the job. If the jobs are failing in a way that they are
put back on the queue because of the TTR timeout the timeout will
increase. I think you might want something like
if (job['releases'].to_i + job['timeouts'].to_i) < 3
do_work(job)
else
job.delete
end
We have done this in some code. Another option that we did once was to
include a field called failed on our job objects. When we knew we
couldn't complete a job we incremented the failed count and put it
back on the queue. I think it is better to use the releases and
timeouts provided by beanstalkd. But if you want to control what is
considered a failed attempt this other way can work too.
Hope that helps.
peace,
Dan Mayer
Co-founder, Devver.net (http://devver.net)
http://twitter.com/devver
http://mayerdan.com
http://twitter.com/danmayer
On Sat, Nov 7, 2009 at 1:18 AM, Parand Darugar <[email protected]> wrote:
>
> I have a scenario where I need to implement retries for jobs in the
> queue - try the job three times, and on the 4th try put it into the
> failed queue. What's a good way to handle this? Is there a place to
> attach meta-data (eg. number of retries) on the job itself, or do I
> have to modify the payload of the job and resubmit it?
>
> This is using the beanstalkc python library.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"beanstalk-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/beanstalk-talk?hl=en
-~----------~----~----~----~------~----~------~--~---