Question

I have a use case which requires placing two different types of jobs in a beanstalk queue, say type a and type b. I put type a job whenever a new one arrives, but for type b I want that there should be a single job of type b in a queue at a time (there should never be two or more jobs of type b in queue). When I go for inserting type b job in queue, I first want to check if there is any type b job already in queue? If it is, then delay that job and don't insert a new one. If there is no type b job in queue, insert a new one. So is it possible to search a job in beanstalk queue?

Was it helpful?

Solution

No, you can't search a queue (Beanstalkd calls them 'tubes'), only get a job (though you can PEEK, to see what the next job would be).

Since you can watch more than one tube at a time though (and get a job from any one of them, depending on priority and age), you could create a tube that would only every contain a type-b job. Then it turns into a simple count - stats-tube [tube-name(eg 'type-b-jobs')]. If that tube has a job in it, it's a typ-b job, and so you can go on with the type-a jobs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top