beanstalkd/beaneater

Is there a "queue is empty" hook?

Closed this issue · 9 comments

I have a bunch of tasks that belong to a user and I'd like to notify him via email when they are all done. My idea is to create a tube, watch it until it's empty, then delete it and send the email.
Is there a way to hook up with a "queue x is empty" event?

I don't think there is, but in my scenario which sounds similar I just make a reserve request for the tube with a short timeout and check the return. If I get a TIMED_OUT response it means it was empty. I suppose you could peek, but then you would be looping.

and how do you handle buried jobs? I suppose you should kick them all before declaring the tube empty when you get a TIMED_OUT response.

I don't have buried jobs in my scenario, but a peek-buried or a kick on TIMED_OUT makes sense.

I "solved" by creating a queue that monitors other queues. A bit "meta", but it works :)

Yes, but do you have a queue to monitor the monitor queue? :)

queue monitor is always there. if the monitored queue is empty the task gets archived, otherwise recreated with the same params and some delay.

Stumbled upon a nasty situation. Monitor task detects a queue is empty and starts a very long upload task. I assume this will not be called anymore and it's the last operation to be performed on the queue, but for some reason a worker sometimes kicks in on exactly the same task I am performing (the upload) and starts to upload the same file again. Any hint?

Uhm, I am gonna try to increase the ttr to 1800 and see how it goes.

Ok, increasing a lot the ttr worked but I had to use a pretty complex if to make sure the queue is really not empty

if tube.stats.current_jobs_urgent > 0 || tube.stats.current_jobs_ready > 0 || tube.stats.current_jobs_reserved > 0 || tube.stats.current_jobs_delayed > 0 || tube.stats.current_jobs_buried > 0 || tube.stats.current_using > 0

Just peeking :ready, :buried and :delayed does not work for me.