Create intermediate Works with: Any AI

Scheduled Script With Logging

Few shot Has example

Create a robust cron-style script.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratings…

Write a robust scheduled script. Language and environment: [LANGUAGE_AND_ENVIRONMENT]. Task: [TASK_DESCRIPTION]. Schedule: [SCHEDULE]. Inputs and outputs: [INPUTS_AND_OUTPUTS]. What should happen on failure: [FAILURE_BEHAVIOR].

The script should follow this pattern, shown briefly:
- Load configuration from environment variables with validation (fail fast with a clear message).
- Set up structured logging with timestamps, a run ID, and levels (info for steps, warning for recoverable issues, error with stack trace).
- Take a lock so two runs cannot overlap.
- Wrap the main work in a function that returns a result summary.
- Retry transient errors with backoff, but not on validation errors.
- Exit with a non-zero code on failure and send an alert (email, chat webhook) with the summary and log location.
- Log the run duration and counts of processed items.
- Make the task idempotent so re-running does not duplicate work.

Provide the full script with comments, the scheduler entry (cron expression or equivalent for my environment) with an explanation, a log rotation setup, a dry-run mode, a test plan (normal run, forced failure, overlapping run, missing config), and a monitoring suggestion to detect if the job did not run at all (heartbeat).

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

See an example result (fictional data)
Design summary: a Python script run nightly at 02:00 by cron (0 2 * * *).
- Config from environment variables; exits with a clear message if REPORT_URL is missing.
- Logging: structured lines "2026-10-15T02:00:03Z run=a1f2 level=INFO step=fetch rows=412".
- Lock file prevents overlapping runs.
- Retries: 3 attempts with backoff on network errors, none on validation errors.
- Idempotent: output file named by date; rerun overwrites.
- Failure: non-zero exit and a chat webhook with the run ID and log path.
- Heartbeat: pings a monitoring URL on success so a missed run raises an alert.
Tests: normal run, forced failure, overlapping run, missing config.

Illustrative only, made-up data. Your results will differ and must be reviewed.

Related prompts