Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed jobs not correctly unlocked first time through (fast repeats) #63

Closed
mathie opened this issue Apr 26, 2010 · 4 comments
Closed

Comments

@mathie
Copy link

mathie commented Apr 26, 2010

I've been tooling around with changing the backoff algorithm (and making the algorithm configurable), but in doing so, I noticed that failed jobs are invariably retried instantly anyway with the currently release (2.0.3) of delayed job.

After a whole bunch of yak shaving, I noticed that the locked_by attribute sometimes wasn't being correctly updated when a failed job was rescheduled. In #reschedule, it's doing:

job.run_at = time
job.unlock
job.save!

job.unlock should have been setting locked_by to nil and, indeed in inspecting the objects, it seems to be setting locked_by to nil (it isn't before and it is after). However, the save operation isn't updating the locked_by in the db. I think this is ActiveRecord's dirty tracking being too clever. I made a quick change to #reserve_and_run_one_job to change from:

run(job) if job

to:

run(job.reload) if job

which seems to do the trick, though I don't fully understand why. :-)

Can you see what's going wrong and if this is the right fix?

@mathie
Copy link
Author

mathie commented May 12, 2010

Any thoughts on this ticket? Or am I just crazy? ;-)

@bkeepers
Copy link

Sorry, I haven't had a chance to take a look at it yet. I'll try to in the next day or so.

@blaxter
Copy link

blaxter commented Sep 16, 2010

it's because the job has been locked with ar's class methods (update_all), and after that the locked_by and locked_at is setted (but no save is perform!) so when you call to unlock, for activerecord you are setting to the original value (nil, which is incorrect because in the database is not nil, is the value setted by update_all), so no save is done.

@bkeepers
Copy link

Fix issue where dirty tracking prevented job from being properly unlocked

Closed by e03a584

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants