Events
Every unit transition and every scaling change is written to an append-only log, in the same database transaction as the change. Read it with a cursor.
curl
Code
TypeScript
Code
Python
Code
The envelope (contract v1)
Code
seq is gapless and strictly increasing per Workload, so a cursor never skips an event that commits late. Consumers must ignore unknown fields and unknown event types: additions are never a new version.
| Type | data |
|---|---|
unit.stopped | {reason} and the facts in How a unit ended |
unit.created, unit.starting, unit.ready, unit.idle, unit.busy, unit.draining | |
unit.accepting, unit.not_accepting | |
unit.allocated, unit.allocation_delivered, unit.allocation_undelivered | |
unit.exited | {code, restarted} and the facts in How a unit ended |
unit.failed | {reason} and the same facts |
unit.destroyed | {reason} (expired when destroyed after being stopped too long, start_deadline when a unit created stopped was not started in time) and the same facts |
units.scaled | {from, to, reason}; unit is null |
rollout.started, rollout.completed, rollout.paused | unit is null |
webhook.ping (webhook deliveries only) | |
events.gap (webhook deliveries only) | {from_seq, to_seq}: events a re-enabled webhook missed because they were no longer kept |
unit.ready and unit.allocated carry the unit's private name and public address, so a matchmaker needs no second read. idle and busy are emitted on transitions only.
Why a unit stopped
unit.stopped carries data.reason:
reason | Meaning |
|---|---|
requested | your program (or you, through the API) stopped it |
exited | its process exited and the unit's on_exit is stop |
service_stopped | the whole Workload was stopped |
memory_limit | it stayed over its memory budget for a sustained period. A unit created by your program is stopped alone; see Limits |
idle | it sat idle past its idle timeout and the policy is stop |
ready_timeout | it did not become ready within its ready timeout |
Events written before the reason was recorded have none, and new reasons may be added: treat an unknown value as a plain stop.
How a unit ended
The events that end a unit (unit.stopped, unit.exited, unit.failed and unit.destroyed) all carry the same facts in data, next to their own fields. The same facts are on the unit itself, as termination, so you can read them without the log.
Code
| Field | Meaning |
|---|---|
ordered_by | who ended it. kind is program (your code, through the unit control API), person (a member of your organization; user_id says which), staff (Zaroz staff acting on your service; no id is given), platform (memory enforcement, the scaling policy, a rollout, a service stop) or process (the process ended by itself) |
reason | the same word as the event's own reason. unit.exited has exited |
phase | how far the unit got: starting (it never became ready), ready, or draining (it was winding down). null if it never had a pod |
exit_code | the process exit code, when one was recorded |
oom_killed | true when the container was killed for running out of memory |
last_heartbeat_at | when the unit's agent last reported before the end. null if the agent never reported |
on_exit | the unit's on_exit at that time: restart, stop or destroy |
Use ordered_by to tell a stop you ordered from one the platform ordered. A health check of your own that fails shows as program; a memory stop shows as platform. last_heartbeat_at comes from the unit's own reports, never from a guess, so a null means the unit never said anything.
unit.destroyed has a reason too: removed (a destroy call), memory_limit, exited, scaled_in, service_deleted, idle, ready_timeout, expired or start_deadline (a unit created stopped with start_within_seconds that never started; see Reservations that never start). Events written before these fields existed carry only their reason (and code for an exit). Their ordered_by is then the usual one for that reason, oom_killed is false and the other facts are null.
Parameters
| Parameter | Meaning |
|---|---|
after | the last seq you saw; 0 starts at the oldest kept event |
types | comma-separated list to keep |
limit | up to 500 |
wait | 0 to 30 seconds: with nothing new, hold the request and return the moment an event arrives |
The response is {events, next_after, oldest_retained_seq}. Send next_after as the next after. Events are kept 30 days. A cursor older than that answers 410 cursor_expired with resume_after.
Delivery is at-least-once
Persist the last seq you processed in the same transaction as your own effect, and treat a repeated seq as already done. This is the same rule that makes webhooks safe.
