Open Workflow Specification

repository·main·Indexed 21 days ago

https://github.com/open-workflow-specification/specification

A CNCF Sandbox project providing a vendor-neutral, community-driven DSL and ecosystem for defining, managing, and executing complex, event-driven workflows. The specification supports service-oriented and FaaS-centric architectures with integration for HTTP, GRPC, OpenAPI, and AsyncAPI. It includes a Conformance Test Kit (CTK) for Gherkin-based verification, multiple language SDKs (.NET, Go, Java, PHP, Python, Rust, TypeScript), and compatible runtimes such as Apache KIE SonataFlow, Lemline, and Synapse.

Tokens
39.8K
Snippets
72
Records
141
Agent score
74%

What's inside Open Workflow Specification

  1. Overview of Open Workflow Specification

    main

    Open Workflow Specification is a vendor-neutral, open-source, and community-driven ecosystem for defining and executing workflows using a Domain Specific Language (DSL). It is designed to be event-driven, service-oriented, and FaaS-centric, allowing for seamless integration with standard protocols like HTTP, GRPC, OpenAPI, and AsyncAPI.

    Key capabilities include:

    • Event-Driven Architecture: Support for various event formats, including CloudEvents.
    • Service Integration: Interaction with services via standard application protocols.
    • Fault Tolerance: Built-in error handling strategies for robust execution.
    • Scheduling: Support for CRON expressions and event-based triggers.
    • Control Flow: Support for conditional branching, event handling, and looping constructs.
  2. Overview of the Open Workflow DSL Reference

    main

    The Open Workflow DSL Reference is a comprehensive guide to the structure, components, and configurations used to define, configure, and manage workflows. It provides detailed property tables and definitions for orchestrating functions and automating processes.

    Key areas covered in the DSL include:

    • Workflow Definitions: Managing the lifecycle, documents, usage, and scheduling of a workflow.
    • Task Definitions: Implementing various task types such as Call, Do, Emit, For, Fork, Listen, Raise, Run, Set, Switch, Try, and Wait.
    • Flow Directives: Controlling the execution path.
    • Lifecycle Events: Monitoring state transitions for both Workflows and Tasks.
    • Connectivity & Security: Configuring external resources, authentication methods (Basic, Bearer, Digest, OAuth2, OpenID Connect), and endpoints.
    • Error & Retry Logic: Defining standard error types and retry strategies.
  3. Use Case: Managing EV Charging Stations

    main

    This use case demonstrates how to automate Electric Vehicle (EV) charging station operations using a serverless workflow. The workflow manages the lifecycle of a charging session—from card scanning and slot acquisition to payment processing and error handling—by interacting with an external EV Power Supplier API.

    Key Actors

    • EV Owner: The user initiating the charge.
    • Charging Station: The physical hardware unit.
    • EV Power Supplier API: The external system managing sessions, slots, and payments.

    Workflow Triggers

    The workflow is activated by two specific event types:

    1. com.ev-power-supplier.charging-station.card-scanned.v1: Triggered when a user scans a card.
    2. com.ev-power-supplier.charging.station-faulted.v1: Triggered when the station reports a fault.

    Core Logic Flow

    1. Initialization: Captures event details into the workflow context.
    2. Session Management:
      • If a card is scanned and an active session exists, the workflow attempts to end the session.
      • If no session exists, it attempts to acquire an available slot.
    3. Slot Acquisition: If a slot is found, it starts a new session. If no slots are available, it triggers a red LED flicker and ends.
    4. Session Lifecycle:
      • Start: Locks the slot, initializes the session, and provides visual feedback (blue LED).
      • End: Ends the session, processes payment, unlocks the slot, and provides visual feedback (white LED).
    5. Error Handling: On a fault, the system contacts support, activates a red LED, and notifies the system of the error.
  4. Compare Open Workflow Specification with other orchestration platforms

    main

    Use this comparison to evaluate the Open Workflow Specification against other major orchestration engines like AWS Step Functions, Google Workflows, Argo Workflows, BPMN, Prefect, and Dagster.

    Key differentiators for Open Workflow Specification include:

    • Cloud Agnosticism: Unlike AWS or Google Workflows, it is not tied to a specific provider, offering high portability.
    • Event-Driven Capabilities: It provides out-of-the-box support for event streaming, complex event processing, and event correlation, which are absent in many other platforms.
    • Data Manipulation: It supports advanced data filtering and mutation using jq and JavaScript.
    • Open Source: It is a CNCF-hosted open-source project, avoiding the vendor lock-in associated with proprietary services.
  5. What is a Workflow in Open Workflow DSL?

    main

    A workflow is a sequence of tasks executed in a defined order (by default, the order they are declared). Workflows are used to automate processes and orchestrate services.

    Workflows can be triggered via:

    • Direct requests
    • Scheduled CRON expressions
    • Event correlation

    Workflows can optionally accept inputs and produce outputs for data processing.

  6. Configure an AsyncAPI Subscription

    main

    An AsyncAPI subscription allows you to listen to an AsyncAPI operation.

    Key Behaviors:

    • An AsyncAPI subscribe operation produces a sequentially ordered array of all consumed messages.
    • If foreach is used, tasks for each message must complete before the next one begins. Messages should be stored in a FIFO queue during this process.

    Properties:

    • filter (string): A runtime expression used to filter consumed messages.
    • consume (subscriptionLifetime): Required. Configures the subscription's lifetime (how long/how many messages to collect).
    • foreach (subscriptionIterator): Configures an iterator for processing each consumed message.
    subscription:
      filter: ${ . == $workflow.input.chat.roomId } 
      consume:
        amount: 5
        for:
          seconds: 10
  7. Configure an Event Consumption Strategy

    main

    An event consumption strategy defines how a workflow waits for events before proceeding. You must choose one of the following modes:

    • all: Wait for all defined eventFilter[] to occur.
    • any: Wait for any of the defined eventFilter[] to occur. If the list is empty, it listens to all incoming events.
    • one: Wait for a single specific eventFilter to occur.

    If any is used, you can provide an until property (a runtime expression or specific events) to define the condition that stops the listener. If until is omitted, the workflow proceeds to the next task as soon as any event is received.

  8. Configure workflow scheduling

    main

    Workflows can be scheduled using four key properties to control execution timing and triggers:

    • every: Defines a fixed interval for periodic execution, regardless of previous run status.
    • cron: Uses CRON expressions for execution at specific times or intervals.
    • after: Specifies a delay duration to wait before restarting a workflow after it completes.
    • on: Enables event-driven scheduling, triggering execution based on external events.

    For detailed syntax, refer to the DSL reference.

  9. Understand Tasks in a Workflow

    main

    A task is a discrete, modular unit of work within a workflow. Tasks are executed in the sequence defined in the do block.

    Common Task Properties:

    • if (string): A runtime expression used to determine if the task should run. If the expression is false, the task is skipped and its output is the raw task input.
    • input (object): Customizes task input and documents its schema.
    • output (object): Customizes task output and documents its schema.
    • export (object): Customizes the content of the workflow context.
    • timeout (string): Task-specific timeout. If a string, it must match a named timeout in the use section.
    • then (flowDirective): The next flow directive to execute. Defaults to continue.
    • metadata (map): Additional task information.

    Mandatory Task Types (Supported by all runtimes):

    • Call: Call services or functions.
    • Do: Sequence of subtasks.
    • Fork: Concurrent subtasks.
    • Emit: Emit events.
    • For: Iterate over collections.
    • Listen: Listen for events.
    • Raise: Raise errors.
    • Run: Run containers, scripts, shell commands, or other workflows.
    • Switch: Conditional branching.
    • Set: Set workflow data.
    • Try: Error handling/graceful continuation.
    • Wait: Pause for a duration.
  10. Use Arrange, Act, and Assert steps in CTK scenarios

    main

    The CTK uses a structured approach to Gherkin steps, categorized into three groups to improve readability and maintainability:

    1. Arrange: Sets up the initial state (e.g., defining the workflow and setting input data).
    2. Act: Triggers the workflow execution.
    3. Assert: Verifies the outcome (e.g., checking if the workflow completed, faulted, or produced specific output).

    This structure helps stakeholders understand the intent of each step in the test flow.

  11. Distinguish between `schedule.on` and start `listen` tasks

    main

    While both enable event-driven behavior, they operate at different stages of the workflow lifecycle:

    Featureschedule.onStart listen task
    PurposeDefines when to create a new workflow instance.Defines what to do after an instance is created.
    ScopeExternal to the workflow instance.Internal to an active workflow instance.
    Error ImpactFaults/timeouts are typically invisible and do not affect the workflow.Faults/timeouts can cause the entire workflow instance to fail.
  12. Identify user roles in the Open Workflow ecosystem

    main

    The specification defines four primary constituencies (users), prioritized in order of importance for design decisions:

    1. Authors: The primary users who author and read workflows. Their needs are the highest priority.
    2. Operators: Users who run and operate runtime implementations of the specification.
    3. Implementors: Developers building specification-compliant runtimes.
    4. Specifications writers: Those working on the Open Workflow Specification itself.

    When encountering design trade-offs, the specification dictates that author needs should be prioritized over operator, implementor, and specification writer needs.