Keep Cron Jobs from Overlapping
Steve Friedl's lockrun is a wrapper for crontabs that uses tiny text files to make sure the previous job has finished before starting a new one.
(via Jeremy Zawodny)
That's pretty cool. I've run into that problem before and had to code my own locking solution. I like the fact that this is generic. I wonder if it could be baked directly into cron?
Posted by: Marc on June 4, 2006 9:54 PM | permalinkMarc:
I feel ya, but cron is so freaking old, it seems almost hubris to try and mess with it. :)
When I've run into this problem, I just copped out and spaced the jobs further apart.
Posted by: Joe Grossberg on June 4, 2006 9:58 PM | permalinkActually, it doesn't really even use "text" files - at no time is the *contents* of the lockfile ever considered (and in particular, there is never any I/O save for creating the file if it's not there).
Instead, it uses file locking to place what you could think of as a Post-It on a region of the file, and all cooperating processes check the Post-It first. Though locking works with varying region (my lock on the first 100 bytes doesn't conflict with your lock of the second 1024 bytes), lockrun uses an all-or-nothing approach.
Since lockrun is the only process using the file for this purpose, any more fine-grainedness would be pointless. So it just locks the whole file.
No more comments! Either someone has violated Godwin's Law, I'm tired of the discussion or, most likely, the ten-week window has closed. You can, however, contact me through email.