Skip to main content

Module ticker

Module ticker 

Source
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) and state.
spawn_heartbeat
Write a heartbeat record to path now and then every interval, until stop is triggered. state is called for each write. Writes go through write_atomic, so a reader never sees a partial record. A failed write is passed to on_error; the next interval tries again.
spawn_ticker
Run tick every interval until stop is triggered. The first tick comes one interval after the spawn. The thread is named rk-ticker.