AshWorkflow.Entities.Timeout (AshWorkflow v0.7.0)

Copy Markdown View Source

Defines a workflow timeout entity with its configuration schema.

The field option

By default, timeouts measure duration against state_entered_at — the timestamp of when the workflow entered its current state. The field option overrides this to measure against any datetime attribute or calculation on the resource.

This enables data-driven deadlines: "3 months since their last session" rather than "3 months since they entered the active state."

The fire_at option

fire_at names a datetime attribute or expression calculation that already holds the deadline instant, rather than an anchor to measure an offset from:

timeout :dormant do
  fire_at :next_check_at
  transition_to :dormant_review
end

The timeout fires once next_check_at has passed, at whatever resolution the selected scheduler polls or arms timers with.

fire_at and fire_after are mutually exclusive, and exactly one of them is required. field is the anchor fire_after measures from, so it has no meaning alongside fire_at and is rejected in combination with it.

AshWorkflow.Scheduler.due_at/2 reads the deadline field with Map.get/2, so a fire_at pointing at an expression calculation only holds a value once that calculation has been loaded. AshWorkflow.Scheduler.Precise.Timeline loads it with the records it arms timers from.

For a recurring action that fires on an interval for as long as a record sits in its step, use AshWorkflow.Entities.Every instead — see its moduledoc for why that is a separate entity rather than a repeat option here.

Summary

Functions

The anchor fire_after is measured from, defaulting to :state_entered_at.

The datetime field this timeout reads: fire_at when it is given, otherwise the fire_after anchor.

Types

duration_unit()

@type duration_unit() :: AshWorkflow.Duration.unit()

t()

@type t() :: %AshWorkflow.Entities.Timeout{
  __spark_metadata__: term(),
  action: atom() | nil,
  check_interval: String.t() | nil,
  field: atom() | nil,
  fire_after: {pos_integer(), duration_unit()} | nil,
  fire_at: atom() | nil,
  name: atom(),
  retry: AshWorkflow.Entities.Retry.t() | nil,
  self_scheduled?: boolean(),
  transition_to: atom() | nil
}

Functions

anchor_field(timeout)

@spec anchor_field(t()) :: atom()

The anchor fire_after is measured from, defaulting to :state_entered_at.

attribute_schema()

deadline_field(timeout)

@spec deadline_field(t()) :: atom()

The datetime field this timeout reads: fire_at when it is given, otherwise the fire_after anchor.

validate_duration(value)