drfeelngood/resque-batched-job — pull request #9 by jakemack (2012-03-19 18:46:04+00:00)
Title: Combine remove_batched_job and batch_complete? into a single function so...

... that their operations are both surrounded by the same mutex

In the old code, the if one worker finished the call to remove_batched_job and got interrupted before asking for the mutex in batch_complete?, then another worker could execute remove_batched_job before the first executed batch_complete?, bringing the batch size to zero for BOTH workers. Admittedly a rare case, but might have happened to me once already. I actually had the after_batch hook performed four times.

I haven't added tests for this as I'm not sure how to simulate threads being interrupted, but all of the current tests still pass.