Reading — step 1 of 5
Read
~1 min readProduction Concerns
Overlap Prevention
A job that takes longer than its interval will get launched again before the previous run finishes. For most jobs (backups, indexing) this is a bug — two instances corrupt each other.
The classic fix: a per-job lock.
def run_job(job):
if job.lock.acquire(blocking=False):
try:
execute(job.command)
finally:
job.lock.release()
else:
logger.warn("skipping %s — previous run still active", job.id)
For multi-process or multi-host setups, use a distributed lock: a row in a database with a unique constraint, or a Redis SETNX with a TTL. The TTL is critical — if the holder crashes without releasing, the lock auto-expires.
Job-level concurrency limit: max_overlap > 1 allows N concurrent instances.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…