WorkflowsExamples

Workflow Examples


Ticket import saga

From Ticket Import Workflow.

sagas:
  ticket_import_flow:
    state: ticket_import
    state_path: _tmp/import_saga
    steps:
      - name: idle
        set: { step: 0 }
 
      - name: parsing
        on: TICKET_PARSE_STARTED
        set: { step: 1 }
 
      - name: matched
        on: TICKET_ARTIST_MATCHED
        set: { step: 2 }
 
      - name: enriched
        on: TICKET_METADATA_ENRICHED
        set: { step: 3 }
 
      - name: complete
        on: TICKET_IMPORT_COMPLETE
        set: { step: 4 }
        end: true
 
      - name: failed
        on: TICKET_IMPORT_FAILED
        set: { step: -1 }
        end: true

Entity scratch fields:

state:
  ticket_import:
    entity_key: import_id
    fields:
      - name: _tmp/saga_step
        type: int
        default: 0
      - name: _tmp/error_code
        type: string
        default: ""

Preflight gate example:

preflight:
  rules:
    - name: must_be_parsing
      when: { expr: "entity._tmp.saga_step != 1" }
      then:
        - op: reject
          code: INVALID_SAGA_STEP

Submit chain — trigger enrichment

After parse completes, fan out to a metadata enrichment intent:

side_effects:
  rules:
    - name: trigger_enrichment
      when:
        - path: /status
          op: eq
          value: parsed
      then:
        - op: submit
          intent_type: ENRICH_TICKET_METADATA
          payload:
            ticket_id: intent.ticket_id
            artist_id: intent.artist_id

Scheduled reminder

- op: schedule
  event_type: REMINDER_SENT
  delay_seconds: 86400
  payload:
    user_id: intent.user_id
    show_id: intent.show_id

See Timers & Scheduling for limits and external scheduler patterns.


Ticket purchase saga

Multi-terminal purchase flow with when: guards on each step:

# sagas/purchase.sagas.causet
sagas:
  purchase_flow:
    state: ticket
    state_path: _tmp/purchase_status
    steps:
      - name: begin_purchase
        on: TICKET_RESERVED
        set:
          _tmp/purchase_status: pending
          _tmp/reserved_at:     event.ts
 
      - name: complete_purchase
        on: PAYMENT_CONFIRMED
        when: { expr: "entity._tmp/purchase_status == 'pending'" }
        set:
          _tmp/purchase_status: complete
          _tmp/completed_at:    event.ts
        end: true
 
      - name: expire_purchase
        on: RESERVATION_EXPIRED
        when: { expr: "entity._tmp/purchase_status == 'pending'" }
        set:
          _tmp/purchase_status: expired
          _tmp/expired_at:      event.ts
        end: true

Declare scratch fields on the entity:

state:
  ticket:
    entity_key: ticket_id
    fields:
      - name: _tmp/purchase_status
        type: string
        default: idle
      - name: _tmp/reserved_at
        type: int
        default: 0

More examples

ExampleWorkflow demonstrated
Ticket ImportFull saga + events
Defining SagasStep DSL reference
Concert AppSubmit chains in actions

Next steps