DOC_INDEX
THEME
DOCS/Example Cookbook/Parallel Execution Examples

Parallel Execution Examples

OrchStep examples for parallel step execution and concurrent health checks


parallel uuild

Parallel Step Execution

# Example: Parallel Step Execution
# Demonstrates: Running multiple steps concurrently using the parallel: block
#
# Key concepts:
#   - Steps inside parallel: run simultaneously
#   - Each parallel step can produce outputs
#   - Outputs merge back for subsequent sequential steps
#   - If any parallel step fails, the block fails
#
# Try:
#   orchstep run build-and-deploy
#   orchstep run build-and-deploy --var version=3.0.0

name: parallel-build-demo
desc: "Build frontend and backend in parallel, then deploy"

defaults:
  version: "2.0.0"
  environment: staging

tasks:
  build-and-deploy:
    desc: "Parallel build followed by sequential deploy"
    steps:
      - name: build_all
        desc: "Build both services in parallel"
        parallel:
          - name: build_frontend
            func: shell
            do: |
              echo "Building frontend v{{ vars.version }}..."
              echo "Compiling TypeScript..."
              echo "Bundling assets..."
              echo "FRONTEND_ARTIFACT=frontend-{{ vars.version }}.js"
            outputs:
              artifact: '{{ result.output | regexFind "FRONTEND_ARTIFACT=(.+)" }}'

          - name: build_backend
            func: shell
            do: |
              echo "Building backend v{{ vars.version }}..."
              echo "Compiling Go..."
              echo "Running unit tests..."
              echo "BACKEND_ARTIFACT=backend-{{ vars.version }}"
            outputs:
              artifact: '{{ result.output | regexFind "BACKEND_ARTIFACT=(.+)" }}'

      - name: deploy
        desc: "Deploy both artifacts"
        func: shell
        do: |
          echo "Deploying to {{ vars.environment }}..."
          echo "Frontend: {{ steps.build_frontend.artifact }}"
          echo "Backend: {{ steps.build_backend.artifact }}"
          echo "Deploy complete!"

parallel health checks

Parallel Health Checks

# Example: Parallel Health Checks
# Demonstrates: Running multiple health checks simultaneously
#
# Key concepts:
#   - Check multiple services at once instead of sequentially
#   - Collect results from all parallel steps
#   - Use assertions to verify all services are healthy
#
# Try:
#   orchstep run check-all

name: parallel-health_checks
desc: "Check multiple service endpoints in parallel"

defaults:
  api_url: "https://api.example.com"
  web_url: "https://www.example.com"
  admin_url: "https://admin.example.com"

tasks:
  check-all:
    desc: "Verify all services are healthy"
    steps:
      - name: health_checks
        desc: "Run all health checks in parallel"
        parallel:
          - name: check_api
            func: shell
            do: |
              echo "Checking API at {{ vars.api_url }}..."
              echo "API_STATUS=healthy"
            outputs:
              status: '{{ result.output | regexFind "API_STATUS=(.+)" }}'

          - name: check_web
            func: shell
            do: |
              echo "Checking web at {{ vars.web_url }}..."
              echo "WEB_STATUS=healthy"
            outputs:
              status: '{{ result.output | regexFind "WEB_STATUS=(.+)" }}'

          - name: check_admin
            func: shell
            do: |
              echo "Checking admin at {{ vars.admin_url }}..."
              echo "ADMIN_STATUS=healthy"
            outputs:
              status: '{{ result.output | regexFind "ADMIN_STATUS=(.+)" }}'

      - name: verify_all_healthy
        func: assert
        args:
          condition: 'steps.check_api.status === "healthy" && steps.check_web.status === "healthy" && steps.check_admin.status === "healthy"'
          desc: "All services must be healthy"

      - name: summary
        func: shell
        do: |
          echo "Health Check Summary:"
          echo "  API:   {{ steps.check_api.status }}"
          echo "  Web:   {{ steps.check_web.status }}"
          echo "  Admin: {{ steps.check_admin.status }}"
          echo "All services operational!"