wowprompt

Scheduled background job with locking, retries and safe reruns

Turns a recurring task such as a nightly report, a sync or a cleanup into a scheduled job that never runs twice at once, can be rerun safely after a failure and tells you when it fails. Use it when a cron script sometimes overlaps itself, half-finishes, or fails silently for days.

Job code with a lock, a checkpoint and retries, the schedule entry, a table of failure cases and their handling, and an alert plan
The output this prompt produced, unedited.

The prompt

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

  1. The schedule entry, with the time zone stated.
  2. 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.
  1. | 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.
  2. 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.
cron jobscheduled tasksbackground jobsidempotencyjob lockingretry logic

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity