Skip to main content

Module worker_registry

Module worker_registry 

Source
Expand description

RFC-025 Phase 3 — Postgres worker-registry bodies + TTL-sweep.

Backs the five EngineBackend worker-registry methods (register_worker, heartbeat_worker, mark_worker_dead, list_expired_leases, list_workers) on Postgres, plus the worker_registry_ttl_sweep reconciler that prunes rows whose last_heartbeat_ms + liveness_ttl_ms has elapsed.

Schema shape lives in migrations/0021_worker_registry.sql (current-state table + append-only event log). Partition key is (fnv1a_u64(worker_instance_id.as_bytes()) % 256) as i16 — identical to the Valkey-side hashing so register / heartbeat / mark_dead / ttl_sweep all land on the same row for the same instance id.

Functions§

heartbeat_worker
list_expired_leases
list_workers
mark_worker_dead
register_worker
ttl_sweep_tick
Per-partition TTL sweep. Mirrors Valkey’s native PEXPIRE behaviour for PG/SQLite: rows whose last_heartbeat_ms + liveness_ttl_ms falls strictly below now_ms are deleted and a ttl_swept event is appended to the audit log.
worker_partition_key
Derive the ff_worker_registry.partition_key for an instance id. Must match the Valkey-side hashing (both paths own the same row).