Rheo.Lease (rheo v1.0.0)

Copy Markdown View Source

A temporary claim on an event for one consumer group.

Fetching work creates a lease with a unique lease_id (fencing token). Only the holder of the current lease may Rheo.ack/2, Rheo.nack/3, or Rheo.reject/3. After expiry, another consumer may obtain a new lease (at-least-once redelivery).

Fields

FieldTypeMeaning
lease_idString.t()Opaque fencing token for this claim
streamString.t()Stream name
groupString.t()Consumer group name
event_idString.t()Id of the leased event
eventRheo.Event.t()Full immutable event payload
consumer_idString.t()Worker that holds the lease
attemptpos_integer()Delivery attempt count (starts at 1)
leased_atDateTime.t()When the lease was granted
expires_atDateTime.t()When the lease becomes reclaimable
receiptterm() | nilOpaque backend-native settle identity (ADR 021)

Example

iex> event = %Rheo.Event{
...>   id: "evt_01",
...>   stream: "market-events",
...>   partition: 0,
...>   sequence: 1,
...>   timestamp: ~U[2026-01-15 12:00:00.000Z],
...>   type: "curve_update",
...>   payload: %{"currency" => "EUR"}
...> }
iex> lease = %Rheo.Lease{
...>   lease_id: "lease_abc",
...>   stream: "market-events",
...>   group: "risk",
...>   event_id: event.id,
...>   event: event,
...>   consumer_id: "risk-worker-1",
...>   attempt: 1,
...>   leased_at: ~U[2026-01-15 12:00:00.000Z],
...>   expires_at: ~U[2026-01-15 12:00:30.000Z],
...>   receipt: "lease_abc"
...> }
iex> {lease.group, lease.event.type, lease.attempt, lease.receipt}
{"risk", "curve_update", 1, "lease_abc"}

Summary

Types

t()

A fenced lease on a single event for a consumer group.

Types

t()

@type t() :: %Rheo.Lease{
  attempt: pos_integer(),
  consumer_id: String.t(),
  event: Rheo.Event.t(),
  event_id: String.t(),
  expires_at: DateTime.t(),
  group: String.t(),
  lease_id: String.t(),
  leased_at: DateTime.t(),
  receipt: term() | nil,
  stream: String.t()
}

A fenced lease on a single event for a consumer group.

Pass this struct to Rheo.ack/2, Rheo.nack/3, or Rheo.reject/3.

receipt is an opaque backend-native settle token (ADR 021). Database backends typically mirror lease_id; native-stream backends may store a Redis ID / PEL claim identity. Do not pattern-match on receipt contents in application code.