One copy at a time
Patterns 5 · 3:01
A job that polls a system has to run as one copy, even when two agents run the integration. singleton: true in the integration's file lets one copy lead, and a standby takes over when the leader's agent stops.
This part of the video couldn't be loaded.
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 Weik.io's own lock
- 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:01Polling work must happen once, not twice,
- 0:04but two agents keep it running when one stops.
- 0:13hello runs a copy on each agent, dev and dev2.
- 0:17Its route logs hello again every three seconds, once from each copy.
- 0:24Weik.io can hold hello to one running copy,
- 0:27with a standby stepping in when its agent stops.
- 0:35A single line in hello's file makes it run one copy at a time,
- 0:39instead of a copy on every agent that takes it.
- 0:42Four kinds default to this: mft, schedule, change tracking, event source.
- 0:52The copies elect a leader through the platform's own lock,
- 0:55kept in your Weik.io installation.
- 1:00The same lock reaches every copy.
- 1:03Every agent starts a copy, one leads and logs,
- 1:06the standby holds its routes and stands by.
- 1:12If the agent behind the leader stops,
- 1:14a standby leads again within about two seconds.
- 1:21hello's file has no singleton line yet, so add one.
- 1:26weikio run uploads, builds and deploys hello,
- 1:30so both copies restart on the new version.
- 1:37weikio get fleet for devtest lists one leader and one standby,
- 1:42both on the new version.
- 1:46The leader's agent stops.
- 1:48hello's log still gets one line a tick, now from one copy.
- 1:53The standby steps up and leads.
- 1:58The fleet list now marks the stopped agent offline with its role blank.
- 2:03The other copy still leads.
- 2:09The stopped agent reads Offline, with No standby above the table.
- 2:17The agent is back.
- 2:19Its copy stands by, and the leader keeps the lead.
- 2:27The returned copy reads Standby.
- 2:30The Leader changes fold lists changes newest first.
- 2:37A single line keeps hello to one running copy, so each message is logged once.
- 2:43The copies elect their leader through the platform's own lock inside your installation,
- 2:48the rest stand by.
- 2:49When a leader's agent stops, a standby takes the lead.