Expand description
Periodic work and a heartbeat record for a daemon host (issue #376).
spawn_ticker runs a closure every interval on its own thread until a StopToken is
triggered. spawn_heartbeat is a ticker that writes a small JSON record (pid, updated_ms
and the caller’s state) atomically to a path, so a supervisor or a client can read it. Both
end on the first tick after the stop and do no work after it. A write failure is reported to
the caller’s on_error and the heartbeat keeps going.
Functions§
- heartbeat_
record - The heartbeat record:
pid,updated_ms(milliseconds since the Unix epoch) andstate. - spawn_
heartbeat - Write a heartbeat record to
pathnow and then everyinterval, untilstopis triggered.stateis called for each write. Writes go throughwrite_atomic, so a reader never sees a partial record. A failed write is passed toon_error; the next interval tries again. - spawn_
ticker - Run
tickeveryintervaluntilstopis triggered. The first tick comes one interval after the spawn. The thread is namedrk-ticker.