One copy at a time
Patterns 5 · 2:58
A job that polls a system has to run as one copy, even when two agents run the integration. One line in the integration's file lets one copy lead, and a standby takes over when the leader's agent stops.
What it covers
- Two copies of hello on the agents
devanddev2, so every message is logged twice - The line
singleton: true, and the four kinds that run one copy by default - A leader and its standbys, elected through the platform's own lock on the hub
- Version 0.1.5 from
weikio run, with the roles leader and standby inweikio get fleet - A takeover when the leading copy's agent stops, after which
weikio logsstill shows one line per tick - The admin UI marking the stopped agent Offline and then Standby once it's back, with the newest leader change listed first
Commands in this video
Terminal
$ weikio run ./hello --no-logs
$ weikio get fleet --env devtest
$ weikio logs sandbox/hello --since 15s --query 'hello again'Transcript
- 0:01A job that polls a system must not run twice.
- 0:07You run it on two agents.
- 0:15Both agents, dev and dev2, run a copy of hello,
- 0:19so every message is logged twice, every three seconds.
- 0:26Weik.io can run one copy at a time. A standby takes over when the leader's agent stops.
- 0:36One copy at a time is the line singleton: true in the integration's own file.
- 0:42Four other kinds run this way by default:
- 0:45mft, schedule, change tracking and event source.
- 0:51A leader and its standbys is what the copies elect through the platform's own lock kept on the hub.
- 1:00Every copy starts,
- 1:01and one copy leads while the others stand by with their routes held.
- 1:06When the leading copy's agent stops,
- 1:09a standby takes the lead within about two seconds.
- 1:16The file has the line singleton: true.
- 1:20The run builds version 0.1.5 and both copies start on it.
- 1:31The fleet list reads ROLE leader on one row and standby on the other.
- 1:41Now the leading copy's agent stops.
- 1:43The other copy takes the lead.
- 1:48The log goes on, one line a tick.
- 1:53A couple of minutes later, the fleet reads the stopped agent as (offline) with no role,
- 1:58and the other copy leads.
- 2:06The stopped agent reads Offline, and the line ends No standby.
- 2:15The agent is back online.
- 2:18Its copy stands by, and the lead stays.
- 2:26The returned copy reads Standby.
- 2:29Leader changes lists the newest change first.
- 2:36One copy at a time logs every hello message once.
- 2:40The copies elect a leader and its standbys through the platform's own lock kept on the hub.
- 2:46When the leading copy's agent stops, a standby takes the lead.