automata/event/builtin/body

Types

Convenience alias used by ecosystem-wide layers (worker, runtime).

pub type BuiltinEvent =
  event.Event(EventBody)

Built-in body sum used by the BuiltinEvent alias.

Closed for known kinds plus a Custom escape hatch. The FileSystem variant carries an automata/fsevent WatchEvent so the full set of ops (Create, Write, Remove, Rename, Chmod) and the rename’s old path can travel together with the event without callers having to invent ad-hoc body kinds.

pub type EventBody {
  Scheduled(
    plan_id: String,
    fired_at: ast.ValidDateTime,
    schedule_kind: ScheduleKind,
  )
  FileSystem(event: event.WatchEvent)
  Manual(
    reason: option.Option(String),
    actor: option.Option(String),
  )
  Custom(kind: String, attributes: dict.Dict(String, String))
}

Constructors

Distinguishes cron and RRULE plans inside Scheduled so a worker can branch without inspecting the producing module.

pub type ScheduleKind {
  CronSchedule
  RRuleSchedule
}

Constructors

  • CronSchedule
  • RRuleSchedule

Values

pub fn custom(
  kind kind: String,
  attributes attributes: dict.Dict(String, String),
) -> EventBody
pub fn derived_source(
  body: EventBody,
  source_id: String,
) -> source.Source

Derive the canonical Source for an EventBody. Exposed so that callers building events via event.new (for advanced cases like attaching a source name) can stay consistent with body.new.

pub fn derived_source_kind(body: EventBody) -> source.SourceKind

Map an EventBody to its canonical SourceKind.

pub fn file_system(event event: event.WatchEvent) -> EventBody

Wrap an automata/fsevent WatchEvent in the canonical body.

pub fn kind(body: EventBody) -> String

Stable string label for routing tables, metrics, and structured logs.

FileSystem(_) becomes "file_system:create" for a single-op event, "file_system:create+write" when several ops are present (lowercase ops joined by + in canonical order). Custom("kind", _) becomes "custom:kind".

pub fn manual(
  reason reason: option.Option(String),
  actor actor: option.Option(String),
) -> EventBody
pub fn new(
  id id: String,
  occurred_at occurred_at: ast.ValidDateTime,
  source_id source_id: String,
  body body: EventBody,
) -> event.Event(EventBody)

Construct a BuiltinEvent whose source.kind is derived from body. This is the only sanctioned constructor for BuiltinEvent because it makes source/body misclassification unrepresentable — Scheduled always pairs with ScheduleSource, FileSystem(_) with FileSystemSource, Custom("vendor.kind", _) with CustomSource("vendor.kind"), etc.

pub fn scheduled(
  plan_id plan_id: String,
  fired_at fired_at: ast.ValidDateTime,
  schedule_kind schedule_kind: ScheduleKind,
) -> EventBody
pub fn scheduled_event(
  id id: String,
  plan_id plan_id: String,
  at at: ast.ValidDateTime,
  schedule_kind schedule_kind: ScheduleKind,
) -> event.Event(EventBody)

Build a Scheduled BuiltinEvent from a single (id, plan_id, at, schedule_kind) tuple.

Equivalent to:

new(
  id: id,
  occurred_at: at,
  source_id: plan_id,
  body: scheduled(plan_id: plan_id, fired_at: at, schedule_kind: kind),
)

In the common case source_id equals plan_id and occurred_at equals fired_at, so the verbose form forces the caller to type the same value twice. This smart constructor halves the surface and removes the “are these intentionally different?” cognitive load. Reach for new/4 only when the two values genuinely differ (delayed dispatch recorded after the fact, fan-out under a different source_id, etc.).

Search Document