Skip to main content

Crate agent_effects_postgres

Crate agent_effects_postgres 

Source
Expand description

PostgreSQL store for agent-effects.

For production services: many workers on many hosts sharing one database.

let store = agent_effects_postgres::PostgresStore::connect("postgres://localhost/effects").await?;

§The database’s clock

By default (ClockSource::Database), every time the store uses comes from Postgres’s clock_timestamp(), not from the calling worker:

  • lease liveness, lease expiry and takeover;
  • the times recorded on transitions;
  • the “no live lease” filter of recovery scans.

Workers whose clocks disagree therefore still agree on who holds a lease. This removes the clock-skew limit that leases otherwise have. Retry schedules (next_attempt_at) are still computed by the worker. ClockSource::Caller uses the times the runtime passes in instead, as the in-memory and SQLite stores do; the conformance suite needs it to drive time.

§Concurrency

Every change is “load the row FOR UPDATE, apply the pure EffectRecord operation, save” in one transaction, so concurrent writers serialize on the row. The update also checks the version it read. Recovery and pending scans read with FOR UPDATE SKIP LOCKED: rows another worker is changing right now are skipped, not waited on.

Structs§

PostgresStore
An EffectStore in a PostgreSQL database.

Enums§

ClockSource
Whose clock the store trusts for leases and recorded times.