Running an integration on a schedule
Patterns 3 · 3:21
A cron expression in the route runs the hello integration at set times, and singleton: true lets one copy lead while a second copy on another agent stands by. Each environment has its own cron value.
This part of the video couldn't be loaded.
What it covers
- Two agents in devtest, so every hello log line appears twice
- A Quartz route with a six-field cron expression from the variable
hello-cron singleton: trueas a new line in the integration's file- A cron value per environment, every minute in devtest and two at night in production
- Leader and standby in
weikio get fleet, and the leader's lines inweikio logs - The leader and the standby in the Placement row of hello's page in the admin UI
Commands in this video
Terminal
$ weikio status sandbox/hello
$ weikio logs sandbox/hello --since 15s
$ weikio variable set sandbox/hello-cron '0 * * * * ?' --env devtest
$ weikio variable set sandbox/hello-cron '0 0 2 * * ?' --env production
$ weikio run ./hello --no-logs
$ weikio get fleet --env devtest
$ weikio logs sandbox/hello --since 67s --query 'hello again'Transcript
- 0:01devtest runs the integration every minute, production at two at night.
- 0:06With two agents running, it has to fire once.
- 0:13hello runs in devtest,
- 0:16taking the message and its key from values in your Weik.io installation.
- 0:23An admin enrolled dev2 so devtest keeps running when dev goes away.
- 0:31weikio status sandbox/hello shows hello's one deployment, running on both agents.
- 0:39weikio logs sandbox/hello reads back the last fifteen seconds.
- 0:45Every message appears twice, alternating between dev and dev2.
- 0:50Each copy runs its own timer.
- 0:57The route no longer starts from a plain timer,
- 0:59but from quartz, Camel's scheduler for cron.
- 1:03It names the variable hello-cron, whose value comes from the installation.
- 1:08integration.yaml adds singleton true,
- 1:11so one copy does the scheduled work while the others wait.
- 1:18The cron lives in a variable, with a value per environment.
- 1:22weikio variable set sandbox/hello-cron writes devtest's value.
- 1:31The same command writes production's value.
- 1:34hello runs nothing there today.
- 1:36Production's value means two at night.
- 1:39Values land at the next start, so both go in first.
- 1:45weikio run ./hello builds the changed folder into version 0.1.5.
- 1:53Both copies restart on it, then the schedule waits for the next minute.
- 2:01weikio get fleet for devtest prints one row per copy in the environment.
- 2:06dev leads, dev2 stands by, and if dev's copy were lost another copy takes the lead.
- 2:15weikio logs sandbox/hello since the run,
- 2:19kept to the logged message, gives two lines.
- 2:23A minute apart, each at second 00, both from dev,
- 2:26where the leading copy runs, and none from dev2.
- 2:34The integration's page in the admin UI names dev, whose copy leads.
- 2:39The Runs row reads a single copy at any moment, set in the integration's file.
- 2:45Placement names the leading agent and the standby.
- 2:51The Variables and secrets section holds both values, each under its environment.
- 2:56Production keeps its value while running nothing.
- 3:03The route starts on a quartz cron.
- 3:05Each environment holds a different value for hello-cron.
- 3:09The singleton line keeps one copy leading and the rest on standby.
Next in this track
Patterns 4 · 3:47 React to database changes Watched