Skip to main content
An agent that answers once is a function call. An agent that answers every ten minutes, forever, without you watching it, is a different thing. CronJob is that second thing.

Overview

The smallest job

run() blocks. Press Ctrl-C to stop, or call job.stop() from another thread.

Interval format

"<number><unit>", where unit is seconds, minutes or hours.
"1 second" (with a space), "1day", "0seconds" and "" are all rejected at construction with a CronJobConfigError. A zero interval used to be accepted and then silently never fire, which is why it is now an error.

Several tasks, one cadence

When one agent has several checks that share a schedule, batched_run registers all of them and runs each on every tick.
For several agents on different cadences, see Multiple Agents on Different Schedules.

Passing arguments through

Anything you pass as a keyword reaches the agent’s run on every tick.

Stopping on a timer

run() blocks, so schedule the stop from another thread.

Checking on it

get_execution_stats() is safe to call from another thread while the job runs.
execution_count is successes. error_count is total failures. The one to watch is consecutive_errors: occasional failures on a long-running job are normal, a rising streak is not.

What happens when the agent fails

Nothing dramatic, by design. The failure is logged with a traceback and the task runs again on the next tick, the way cron behaves. A rate limit or a dropped connection does not end your job. If you want a job to give up when it is failing every time, give it a budget:
When that budget is exhausted the job stops and run() raises CronJobExecutionError, so a dead schedule is never mistaken for a healthy one. The default is None, which retries forever. See Failure Handling and Monitoring for the full pattern.

Next steps

Multiple Agents

Several agents, each on its own cadence, in one process

Failure Handling

Error budgets, live monitoring, and non-blocking fleets

CronJob Reference

Full parameter and method documentation

Runnable Examples

The example files in the repository