Running a script on a cron schedule
Patterns 7 · 3:18
A schedule runs a script on an agent at set times, and each run leaves logs and a run record. Only exit code 0 is a success, and any other code fails the run.
This part of the video couldn't be loaded.
What it covers
- The script that cleans up old export files on a devtest server
- The schedule the Weik.io CLI writes with
weikio init - The six-field cron in UTC, which the admin UI says in words
- The deployment's logs, read with
weikio logsor the schedule's Logs section - Each run record in the Runs section, with its exit code and outcome
- The failed run in the Runs section, listed with exit code 3
Commands in this video
Terminal
$ weikio init cleanup --kind schedule
$ weikio run ./cleanup --no-logs
$ weikio logs finance/cleanup --since 1mTranscript
- 0:01A script must run at set times on a server, and a failed run must show as failed.
- 0:11A script on a devtest server in your Weik.io
- 0:14installation cleans up old export files.
- 0:17When the script fails, exit code 3 stays on that server.
- 0:21Weik.io runs the script from a schedule and keeps logs and a run record.
- 0:30The Weik.io CLI writes the schedule with weikio init.
- 0:40The schedule runs a command on an agent, so you write no route.
- 0:45The cron has six fields, seconds first, in UTC, and runs every minute at second 0.
- 0:52The admin UI says the cron in words.
- 1:00The deployment's logs collect every line the script writes,
- 1:03to standard output or standard error.
- 1:06The closing line says how the command ended: 0, or another code with the error.
- 1:12Read the log lines with weikio logs or the schedule's Logs section.
- 1:19Each run leaves a run record with its start and end, its exit code and outcome.
- 1:25The run records are in the admin UI's Runs section, newest first.
- 1:31Only exit code 0 is a success, and any other code fails the run.
- 1:40weikio run publishes the folder, then deploys it to devtest.
- 1:51The agent runs the script when the cron fires, and the run's lines reach the logs.
- 2:00The run record marks a success, and weikio logs fetches those lines.
- 2:11The script can't open its exports folder and exits with 3.
- 2:15The closing line gives the exit code and error.
- 2:19The run record marks the failure.
- 2:25Once the exports folder is back,
- 2:27you use Run now to start the command without waiting for the cron,
- 2:32and see what it printed.
- 2:39Every run is in the Runs section, and the failed one is listed with exit code 3.
- 2:47The cron appears in words in the Integrations list, with the schedule's command.
- 2:57A schedule with its cron runs the command on the agent's host.
- 3:01The logs carry what the command printed, closing with the exit code.
- 3:05A run record keeps the outcome, and every run is in the Runs section.