Running an integration on a schedule
Patterns 3 · 3:15
A cron expression in the route runs the hello integration at set times, and one line lets one copy lead while a second copy on another agent stands by. Each environment has its own cron value.
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 the one 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:01A job must run at set times, and only once.
- 0:05Two agents run hello, so it logs twice.
- 0:12Hello runs in the devtest environment, reading a variable and a secret.
- 0:20An admin added dev2 so devtest runs if dev goes away.
- 0:27weikio status shows the devtest deployment.
- 0:31Its version reads 0.1.4 on both agents.
- 0:36The log holds every message twice, once per agent.
- 0:40Both copies log on their own timers.
- 0:46The route now starts from Quartz, the scheduler Camel uses for a cron.
- 0:51Its cron is six fields with seconds first.
- 0:54The cron comes from the variable hello-cron.
- 0:58The integration file adds singleton: true as its one new line.
- 1:02That line lets one copy run the schedule while the other waits.
- 1:07Each environment can hold its own value for the cron.
- 1:12In devtest the schedule runs every minute.
- 1:20When hello runs in production it reads two at night.
- 1:24Both values go in before the run, because a value arrives at the next start.
- 1:30The run builds a new version and the deployment follows it.
- 1:37Both copies restart on 0.1.5, and the schedule waits for its minute.
- 1:47weikio get fleet lists every copy of every deployment.
- 1:51The ROLE column reads leader for dev and standby for dev2.
- 1:56The leader runs the schedule.
- 1:58The standby waits and takes over if the leader's agent goes away.
- 2:04weikio logs reads the log since the run.
- 2:09The two lines sit one minute apart, at second 00.
- 2:14Both lines come from dev, the copy that leads.
- 2:17Each line names its route and then its agent.
- 2:25hello's page in the admin UI reads dev leads in its Environments strip.
- 2:30The Runs row says one copy at a time, set by the integration.
- 2:35The Placement row names the leader and the standby.
- 2:41The Variables and secrets section shows both values of hello-cron.
- 2:46The section gives each environment its own column.
- 2:49Production holds the value and runs nothing.
- 2:56The route starts from Quartz with a cron.
- 2:59The cron comes from a variable with its own value in each environment.
- 3:03singleton: true lets one copy lead while the standby waits.
Next in this track
Patterns 4 · 3:49 React to database changes Watched