Cyclium.WorkClaims.Heartbeat (Cyclium v0.1.6)

Copy Markdown View Source

Periodically renews a work claim lease while an episode is executing.

Started by EpisodeTask after a successful claim acquisition, and stopped when the episode completes or fails. The renewal interval defaults to lease_seconds / 3 to ensure the lease stays alive with margin for transient delays.

Crash resilience

The heartbeat is linked to the calling process (EpisodeTask). If the heartbeat crashes, the EpisodeTask receives an EXIT and restarts it. If the EpisodeTask crashes, the heartbeat dies with it. This ensures the heartbeat lifecycle is always tied to the episode execution.

Options

  • :dedupe_key — the claimed dedupe key (required)
  • :owner_node — the node that holds the claim (required)
  • :lease_seconds — lease duration for renewals (required)
  • :interval_ms — renewal interval in ms (default: lease_seconds * 1000 / 3)
  • :task_pid — the EpisodeTask process to notify if the claim is lost (optional). On :not_owner, the heartbeat sends {:cyclium_claim_lost, dedupe_key} to this pid so the running episode can abort before delivering outputs (it otherwise has no way to learn the lease was stolen out from under it).

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

stop(pid)