noblesamurai/node-pg-jobs — pull request #11 by aeh (2014-07-30 07:21:41+00:00)
Title: Safer locking

We seem to be processing some things twice if we have multiple consumer processes.

This seems to occur when process 1 releases its lock on a job after process 2 has started a transaction but before it has itself gotten a job. ie. The locked job entry from process 1 becomes unlocked but due to process 2 already being in a transaction it only sees the job as it was there before process 1 finished and thinks it still needs to be processed.

Making sure we get the lock outside of the transaction means we are always working off the current state of any unlocked job entries.