Fill in these first
- Language and runtime: [e.g. PHP 8 command run by cron, Node.js worker, Python script]
- What the job does: [e.g. every night at 2:00 sends unpaid invoice reminders, every 15 minutes syncs orders from a marketplace]
- How long it takes now: [e.g. 2 to 40 minutes]
- Data it touches: [tables, files or external APIs]
- Where it runs: [one server, several servers, a container platform]
- How you want to hear about failures: [e.g. email, chat webhook, a status table]
Task
Rewrite the job so it is safe to schedule, safe to rerun and easy to watch.
Output format
- The schedule entry, with the time zone stated.
- The job code with comments, covering:
- a lock so a second run exits if the first is still going, with an expiry so a crashed run does not block forever;
- idempotent work: each item marked done, so a rerun skips finished items and never sends a reminder twice;
- processing in small batches with a checkpoint;
- retries with backoff for temporary errors only;
- a clear exit code and a one-line summary at the end.
- | Failure | What happens | How it recovers |, covering a crash midway, an external API down, two servers starting at once, a run longer than the interval.
- An alert rule: fail on error, and also when no successful run has been recorded within the expected time.
Rules
- Read secrets from environment variables, never from the code.
- Keep each batch inside a transaction where the store supports it.
- Log counts and IDs, not personal data.
- State any assumption about volume or timing.






