Skip to content
Weik.ioUniversity
Try Weik.io

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.

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

Sign in to the live demo

Sign in with the shared viewer account, which can open every screen of the example projects and can't change anything.

E-mail
viewer@demo.weik.io
Password
try-weikio-live-demo
Open the live demo