Queues and jobs: KScript.Queue
Running workers
kscript worker runs jobs from the default connection and queues until you press Ctrl+C:
| Command | What it does |
|---|---|
kscript worker | The default connection and queues, until Ctrl+C. |
kscript worker --queue high,default --concurrency 4 | High before default, four jobs at a time. |
kscript worker --stop-when-empty | Run what is there, then stop. |
kscript worker --once | One job, for cron. |
kscript serve --with-worker | A worker inside the server. |
The worker prints a line for each job: when it started, whether it finished, how long it took, and when a failed one will be tried again. Ctrl+C lets the running jobs finish first. --max-jobs and --max-time stop the worker after a while, so a process manager can start a fresh one, and --connection picks a connection other than the default. Every option is in the CLI reference.
Each attempt runs in a fresh interpreter that loads the job's file again, so a worker picks up a changed job the next time it runs it. Still restart a long-running worker after a deploy, for the settings it read when it started.
If a worker stops in the middle of a job, such as when the machine restarts, the job is held for its timeout plus 30 seconds. It then goes back on the queue for the next worker, and counts as a try.
To dispatch a job at set times, such as every hour or at 03:00 each day, list it in the project's schedule file and run kscript schedule work. See Scheduling tasks.