Design a Cron Job / Scheduled Task
Implement a reliable scheduled job with idempotency, error handling, and distributed locking.
The Prompt
Implement a reliable scheduled/cron job for the following task. Include: 1. Idempotency — safe to run multiple times or if the previous run is still in progress 2. Distributed locking to prevent duplicate execution across multiple instances 3. Error handling with alerting 4. Progress tracking and logging 5. Graceful shutdown handling 6. Health check / last-run monitoring Task description: [DESCRIBE THE JOB — e.g., Every day at 2 AM, send a digest email to each user summarizing their activity from the previous day. Must not send duplicate emails if the job runs twice.] Framework/language: [NEXTJS CRON / NODE-CRON / PYTHON APScheduler / etc.] Locking backend: [REDIS / POSTGRESQL ADVISORY LOCKS / etc.]
Example Output
Implemented a Node.js cron job with Redis SETNX distributed locking (10-minute TTL), a job_runs PostgreSQL table for idempotency checks, structured logging with job_id, chunk-based user processing to avoid memory issues, and PagerDuty alert on 3 consecutive failures.
FAQ
Which AI model is best for Design a Cron Job / Scheduled Task?
Claude Sonnet 4 — thinks carefully about concurrency and reliability edge cases.
How do I use the Design a Cron Job / Scheduled Task prompt?
Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Implemented a Node.js cron job with Redis SETNX distributed locking (10-minute TTL), a job_runs PostgreSQL table for idempotency checks, structured logging with job_id, chunk-based user processing to avoid memory issues, and PagerDuty alert on 3 consecutive failures.
Model Recommendation
Claude Sonnet 4 — thinks carefully about concurrency and reliability edge cases.