Defining tasks
Each Task says when it runs, with cron or every, and what it does, with job or run.
| Argument | What it does |
|---|---|
cron |
When it runs, as a cron schedule: '0 3 * * *' (03:00 each day), '*/15 9-17 * * mon-fri', '@hourly', '@daily'. |
every |
How often it runs instead, in whole minutes: 1m, 5m, 1h, 1d. |
job |
A job to dispatch each time, such as PruneSessions(). It goes on the job's queue, and kscript worker runs it. |
run |
A function the scheduler calls each time, with no arguments: @check_feeds, or @reports.nightly for a function of an imported script. |
name |
The task's name in kscript schedule list and the scheduler's output. Defaults to the job's or the function's name. Two tasks can't share a name. |
without_overlapping |
Skip the task while its last run is still going. |
queue, connection |
The queue and connection its job goes to, instead of the job's own. |
description |
What the task is for, shown by kscript schedule list. |
every counts from midnight, so every: 15m runs at :00, :15, :30 and :45, and every: 1d runs at midnight. Times are the machine's local time, as in a crontab.
Jobs or functions
A task with job only dispatches: the work happens in kscript worker, with the job's retries, backoff and timeout. Prefer it for anything that may fail or take a while. The job is built when the task is due, so its fields can depend on the time:
<KScript.Schedule>
<import path="jobs/send-digest.kscript" />
<Task cron="0 8 * * mon" job="SendDigest(kind: 'weekly')" queue="mail" />
</KScript.Schedule>import KScript.Queue
import "jobs/send-digest.kscript"
Schedule {
Task(cron: '0 8 * * mon', job: SendDigest(kind: 'weekly'), queue: 'mail')
}A task with run calls its function in the scheduler itself. It suits short work: an error is reported, and the task runs again at its next time.
Preventing overlaps
With without_overlapping, a task whose last run hasn't finished is skipped, and the scheduler prints SKIP. For a job, the last run lasts until a worker has finished the job it dispatched. The lock is the queue's unique job lock, so with a file or database connection it holds across processes and machines. A lock is let go after 24 hours at the most, so a crashed run can't stop a task for good.