Skip to main content
Event-driven workflows enable reactive, asynchronous patterns where workflows respond to external events, wait for multiple correlated events, or run on schedules.

Event Scheduling

Trigger workflows based on time schedules or incoming events.
schedule-cron.yaml
document:
  dsl: '1.0.3'
  namespace: examples
  name: cron-schedule
  version: '0.1.0'
schedule:
  cron: 0 0 * * *
do:
  - backup:
      call: http
      with:
        method: post
        endpoint: https://example.com/api/v1/backup/start
What it demonstrates:
  • Time-based workflow scheduling with schedule.cron
  • Standard cron expression format (0 0 * * * = daily at midnight)
  • Automated recurring workflows
Use case: Daily backups, periodic cleanup jobs, scheduled reports.

Listening to Single Events

Wait for a specific event before proceeding.
listen-to-one.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: listen-to-one
  version: '0.1.0'
do: 
  - waitForStartup:
      listen:
        to:
          one:
            with:
              type: com.virtual-wf-powered-race.events.race.started.v1
  - startup:
      call: http
      with:
        method: post
        endpoint:
          uri: https://virtual-wf-powered-race.com/api/v4/cars/{carId}/start
What it demonstrates:
  • Waiting for a single event with listen.to.one
  • Event type filtering
  • Workflow pauses until the event arrives
  • Event data becomes available to subsequent tasks
Use case: Coordinating distributed systems, waiting for external approvals, or manual triggers.

Listening to Any Event (First Wins)

listen-to-any.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: listen-to-any
  version: '0.1.0'
do:
  - callDoctor:
      listen:
        to:
          any: []
What it demonstrates:
  • Listening to any event without filters
  • First event received triggers workflow continuation
  • Catch-all event listener

Listening to All Events (Correlation)

Wait for multiple related events before proceeding.
listen-to-all.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: listen-to-all
  version: '0.1.0'
do:
  - callDoctor:
      listen:
        to:
          all:
          - with:
              type: com.fake-hospital.vitals.measurements.temperature
              data: ${ .temperature > 38 }
          - with:
              type: com.fake-hospital.vitals.measurements.bpm
              data: ${ .bpm < 60 or .bpm > 100 }
What it demonstrates:
  • Waiting for multiple events with listen.to.all
  • Different event types in correlation set
  • Data filtering per event type
  • All conditions must be met before proceeding

Emitting Events

Publish events from within workflows.
emit.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: emit
  version: '0.1.0'
do:
  - emitEvent:
      emit:
        event:
          with:
            source: https://petstore.com
            type: com.petstore.order.placed.v1
            data:
              client:
                firstName: Cruella
                lastName: de Vil
              items:
                - breed: dalmatian
                  quantity: 101
What it demonstrates:
  • Publishing CloudEvents with emit
  • Setting event metadata (source, type)
  • Including structured data in events
  • CloudEvents specification compliance
Use case: Notifying other systems, triggering downstream workflows, or audit logging.

Continuous Event Processing

Process events in a loop until a condition is met.
listen-to-any-until-condition.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: consume-until-condition
  version: '0.1.0'
do:
  - getParcel:
      listen:
        to:
          any: []
      until: ${ .status == "failed" or .status == "delivered" }
What it demonstrates:
  • Consuming events repeatedly with until
  • Conditional termination based on event data
  • Processing stream of events until completion

Complex Event-Driven Example

Combining events with iteration and processing.
for.yaml
document:
  dsl: '1.0.3'
  namespace: test
  name: for-example
  version: '0.1.0'
do:
  - checkup:
      for:
        each: pet
        in: .pets
        at: index
      while: .vet != null
      do:
        - waitForCheckup:
            listen:
              to:
                one:
                  with:
                    type: com.fake.petclinic.pets.checkup.completed.v2
            output:
              as: '.pets + [{ "id": $pet.id }]'
What it demonstrates:
  • Combining iteration (for) with event listening (listen)
  • Processing events for each item in a collection
  • Building results incrementally with output transformation
  • Conditional loop continuation with while
Use case: Batch processing with event confirmation, multi-item workflows, or parallel event coordination.

Summary

Event-driven patterns enable:
  • Reactive Workflows - Respond to external events automatically
  • Event Correlation - Wait for multiple related events
  • Scheduled Execution - Run workflows on time-based or event-based triggers
  • Event Publishing - Emit events to notify other systems
  • Stream Processing - Continuously process event streams
  • Asynchronous Coordination - Coordinate distributed, long-running processes
These patterns are essential for building scalable, loosely-coupled systems that react to real-time events.

Build docs developers (and LLMs) love