class

Prostore::Migration::HeartbeatFiber

Inherits Reference < Object

Background fiber that renews the migration lease while a long step is running (ADR-0009 invariant 5).

Without a heartbeat, the lease only renews between steps in the runner's loop. A single multi-minute step (large eager-Crystal-lambda backfill, slow CREATE INDEX CONCURRENTLY, big table rebuild on SQLite) can outlast the lease and lose it to another runner.

The fiber wakes every interval (default 1 minute), tries to claim a connection from the pool, calls Lease.heartbeat. If the pool can't spare a connection (e.g., in-memory SQLite with pool size 1) the heartbeat is silently skipped — the runner's between-steps heartbeat is still in play, which is sufficient for the SQLite case where steps are fast anyway. If Lease.heartbeat reports the lease was stolen, the fiber sets lost? and the runner aborts before the next step.

Cleanly stoppable via a Channel; stop waits for the fiber to actually exit so the connection can be closed safely.

Constants

DEFAULT_INTERVAL = 1.minute

Constructors

new(conn : Connection, migration_id : Int64, runner_id : String, interval : Time::Span = DEFAULT_INTERVAL, lease_duration : Time::Span = Lease::DEFAULT_DURATION)
Source

Instance methods

lost?
Source
start
Source
stop
Source