Ankusa.SDK.LifecycleEvent (ankusa_sdk v0.6.0)

Copy Markdown View Source

A lifecycle event: the CloudEvents 1.0 (structured mode) event an Ankusa instance publishes when a source or a route is created, updated or deleted, when a tenant is erased, or when the instance is restored from a backup.

It arrives as the body of a queue message from the instance's lifecycle sinks (content type application/cloudevents+json, source_id ankusa:lifecycle): decode the message with Ankusa.SDK.Message.decode/1, take hook.body from Ankusa.SDK.Message.to_hook/2, and hand it to decode/1.

{:ok, event} = Ankusa.SDK.LifecycleEvent.decode(hook.body)
event.type     #=> "io.ankusa.source.created"
event.subject  #=> "acme.stripe"
event.data     #=> the entity as the admin API shows it, secrets redacted

Delivery is at least once and in commit order: id is derived from the change, so the same event always has the same id, and revision (per subject) lets a consumer ignore a stale update. sequence is the instance's audit sequence number as the decimal string it is on the wire.

decode/1 ignores keys it does not know and event types it does not know, so a consumer keeps working when a newer node announces more. Anything else wrong is an Ankusa.SDK.InvalidMessageError (never retryable) whose code is "invalid_json", "not_an_object", "unsupported_version" (the event's specversion is not "1.0") or "invalid_field" with the offending field.

Summary

Functions

Decode one lifecycle event (the JSON of the CloudEvent).

Types

t()

@type t() :: %Ankusa.SDK.LifecycleEvent{
  actor: String.t() | nil,
  data: map() | nil,
  datacontenttype: String.t() | nil,
  id: String.t(),
  instance: String.t() | nil,
  replayid: String.t() | nil,
  revision: pos_integer() | nil,
  sequence: String.t() | nil,
  source: String.t(),
  specversion: String.t(),
  subject: String.t(),
  time: String.t(),
  traceparent: String.t() | nil,
  tracestate: String.t() | nil,
  type: String.t()
}

Functions

decode(data)

@spec decode(binary()) :: {:ok, t()} | {:error, Ankusa.SDK.InvalidMessageError.t()}

Decode one lifecycle event (the JSON of the CloudEvent).

The checks run in a fixed order and the first failure wins.