Locking

24 views
Skip to first unread message

Russell Smith

unread,
Jul 3, 2013, 1:54:07 PM7/3/13
to queue_...@googlegroups.com
Hey all,

How do you do locking - i.e. ensuring only one job of a certain type is enqueued?

We've added some code to support this (un-released as yet) which checks for items with matching arguments in the same queue, that are either unlocked or locked for under a certain time. Seems to work pretty well, but doesn't support JSON column type at the moment.

I'd love to hear your solutions or if anyone is interested in us cleaning up the code and releasing.


Russ

Ryan Smith

unread,
Jul 5, 2013, 10:38:17 PM7/5/13
to queue_...@googlegroups.com
Great question Russell. I go back and forth on solutions for this type of problem. Basically, you are wanting to ensure some consistency in your database for your application. You can certainly solve this by making sure you don't enqueue a particular job more than once, or you can make the job idempotent. E.g. The job checks some database condition before it proceeds with the job. I tend to favor the latter approach more than the former as it brings your business logic outside of the infrastructure and inside the app. For instance, what if you want to run that job via a Cron process or a console session instead of your queue?

But, I am certainly not familiar with the details of your problem. Care to share a little more background here? I am very curious to know more to explore the potential of a general solution.


--
You received this message because you are subscribed to the Google Groups "queue_classic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to queue_classi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Russell Smith

unread,
Jul 5, 2013, 10:44:43 PM7/5/13
to queue_...@googlegroups.com
Hey Ryan,

We have jobs that are triggered via cron. One of these is a management task creates / destroys various expensive (time/computationally wise). This task takes a varying amount of time depending on how loaded our servers are so, we queue it. However, without locking there is a possibility that there might still be the same task more than once, which would generally not be a good thing (™).

I was interested in how others solved the same issue and also why they needed to :-)

I'll tidy up the code sometime soon and release if there is interest!!



Russ
Rainforest | +1-650-919-3216 | rainforestqa.com
> You received this message because you are subscribed to a topic in the Google Groups "queue_classic" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/queue_classic/xhFqThkfCKI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to queue_classi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages