collectiveidea/delayed_job_active_record — pull request #43 by robdimarco (2013-03-18 23:43:13+00:00)
Title: Time between when a job is selected and when it is locked can result in a ActiveRecord::RecordNotFound exception

I was running in to an issue where my worker was exiting. Upon investigating, it turned out occasionally, when trying to reserve a job, an ```ActiveRecord::RecordNotFound``` exception was being thrown in the ```reserve``` method in ```delayed/backend/active_record.rb```. The problem was a race condition between when we selected the job and when we locked the job. What was happening was that, on occasion, in between when the worker selected the job and when it tried to lock the job, another worker swooped in and deleted the job. The result was the ActiveRecord::RecordNotFound error that would halt my worker.

This patch resolves the issue by catching the exception and exiting the reserve method as if the job does not exist.

I have patched both master and 0-4-stable with this issue.