collectiveidea/delayed_job_active_record — Issue #14: Failed jobs not correctly unlocked first time through
Author: julienfromentc
Created: 2012-03-07 15:19:42+00:00
State: open

When I tried to upgrade rails to version 3.2.2 (from version 3.1.3), I notice that when a job failed it was run a second right away.

The cause of this problem is that the job is not being unlocked correctly. I found an old issue that had the problem that I described here https://github.com/collectiveidea/delayed_job/issues/63.

What I found is that when first locking the job, only the locks on the database are changed, not those of the object itself, so when the job is unlocked, the locked_by and locked_at attributes are not correctly updated.

I managed to work around the issue by calling `self.reload` instead of :
```self.locked_at = now
self.locked_by = worker
self.locked_at_will_change!
self.locked_by_will_change!
```

This fix may cause a performance issue, and there is probably a better/cleaner way to solve this.

using :
rails version 3.2.2
delayed_job version 3.0.1
delayed_job_active_record version 0.3.2
using SQLite3