Skip to content
Weik.ioUniversity
Try Weik.io

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.

Download the mp4Recorded on 2026.2

What it covers

  • Two copies of hello on the agents dev and dev2, 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 in weikio get fleet
  • A takeover when the leading copy's agent stops, after which weikio logs still 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
  1. 0:01A job that polls a system must not run twice.
  2. 0:07You run it on two agents.
  3. 0:15Both agents, dev and dev2, run a copy of hello,
  4. 0:19so every message is logged twice, every three seconds.
  5. 0:26Weik.io can run one copy at a time. A standby takes over when the leader's agent stops.
  6. 0:36One copy at a time is the line singleton: true in the integration's own file.
  7. 0:42Four other kinds run this way by default:
  8. 0:45mft, schedule, change tracking and event source.
  9. 0:51A leader and its standbys is what the copies elect through the platform's own lock kept on the hub.
  10. 1:00Every copy starts,
  11. 1:01and one copy leads while the others stand by with their routes held.
  12. 1:06When the leading copy's agent stops,
  13. 1:09a standby takes the lead within about two seconds.
  14. 1:16The file has the line singleton: true.
  15. 1:20The run builds version 0.1.5 and both copies start on it.
  16. 1:31The fleet list reads ROLE leader on one row and standby on the other.
  17. 1:41Now the leading copy's agent stops.
  18. 1:43The other copy takes the lead.
  19. 1:48The log goes on, one line a tick.
  20. 1:53A couple of minutes later, the fleet reads the stopped agent as (offline) with no role,
  21. 1:58and the other copy leads.
  22. 2:06The stopped agent reads Offline, and the line ends No standby.
  23. 2:15The agent is back online.
  24. 2:18Its copy stands by, and the lead stays.
  25. 2:26The returned copy reads Standby.
  26. 2:29Leader changes lists the newest change first.
  27. 2:36One copy at a time logs every hello message once.
  28. 2:40The copies elect a leader and its standbys through the platform's own lock kept on the hub.
  29. 2:46When the leading copy's agent stops, a standby takes the lead.