.do
DeployCode Deployment

Deploy as Workflows

Orchestrate MDX Functions as durable multi-step workflows

Deploy MDX as Workflows

Documentation Status: This documentation describes the planned API design for the .do platform. Code examples represent the intended interface and may not reflect the current implementation state. See roadmap for implementation status.

Transform your MDX functions into reliable, durable workflows that survive failures, automatically retry, and provide complete observability.

Overview

Deploy MDX as workflows to create:

  • Order Fulfillment - Multi-step e-commerce processes
  • Content Pipelines - Automated content creation and distribution
  • Data Processing - ETL and data transformation jobs
  • Approval Workflows - Human-in-the-loop processes
flowchart TB A[Workflow Trigger] --> B[Step 1: Validate] B --> C{Success?} C -->|No| D[Retry] D --> B C -->|Yes| E[Step 2: Process] E --> F[Step 3: Store] F --> G{Human Review?} G -->|Yes| H[Wait for Approval] H --> I{Approved?} I -->|No| J[Reject] I -->|Yes| K[Step 4: Complete] G -->|No| K K --> L[Workflow Complete]

Basic Workflow

---
title: Order Fulfillment Workflow
description: Process orders from payment to delivery
---

export async function validatePayment(orderId: string) {
  const order = await $.db.orders.findById(orderId)
  const payment = await $.payment.validate(order.paymentId)

if (!payment.valid) {
throw new Error('Payment validation failed')
}

return { orderId, paymentId: payment.id, amount: payment.amount }
}

export async function reserveInventory(orderId: string) {
  const order = await $.db.orders.findById(orderId)

for (const item of order.items) {
const reserved = await $.inventory.reserve({
productId: item.productId,
quantity: item.quantity,
orderId
})

    if (!reserved) {
      throw new Error(`Insufficient inventory for ${item.productId}`)
    }

}

return { orderId, items: order.items }
}

export async function createShipment(orderId: string) {
  const order = await $.db.orders.findById(orderId)

const shipment = await $.shipping.create({
orderId,
address: order.shippingAddress,
items: order.items
})

return { orderId, shipmentId: shipment.id, trackingNumber: shipment.trackingNumber }
}

export async function sendConfirmation(orderId: string, shipmentId: string) {
  const order = await $.db.orders.findById(orderId)
  const shipment = await $.shipping.getById(shipmentId)

await $.email.send.message({
to: order.customer.email,
subject: 'Order Shipped!',
template: 'order_shipped',
data: {
orderNumber: order.orderNumber,
trackingNumber: shipment.trackingNumber,
estimatedDelivery: shipment.estimatedDelivery
}
})

return { orderId, notified: true }
}

Deploy as Workflow

export const orderFulfillmentWorkflow = $.workflow('order-fulfillment', async (orderId: string) => {
  // Step 1: Validate payment
  const payment = await $.step('validate-payment', () => validatePayment(orderId))

  // Step 2: Reserve inventory
  const inventory = await $.step('reserve-inventory', () => reserveInventory(orderId))

  // Step 3: Create shipment
  const shipment = await $.step('create-shipment', () => createShipment(orderId))

  // Step 4: Send confirmation
  await $.step('send-confirmation', () => sendConfirmation(orderId, shipment.shipmentId))

  // Step 5: Update order status
  await $.step('update-status', () => $.db.orders.update(orderId, { status: 'shipped' }))

  return {
    orderId,
    status: 'completed',
    shipmentId: shipment.shipmentId,
    trackingNumber: shipment.trackingNumber,
  }
})

Workflow Features

Automatic Retries

export const workflow = $.workflow('resilient-workflow', async (input) => {
  // Automatically retries on failure
  await $.step('flaky-operation', () => externalApiCall(input), {
    retry: {
      attempts: 3,
      backoff: 'exponential', // 1s, 2s, 4s
      maxDelay: 60000,
    },
  })
})

Conditional Logic

export async function moderateContent(contentId: string) {
  const content = await $.db.content.findById(contentId)

// AI moderation
const moderation = await $.ai.moderate(content.text)

if (moderation.violations.length === 0) {
// Auto-approve
await $.db.content.update(contentId, { status: 'approved' })
return { action: 'auto_approved' }
}

if (moderation.severity === 'high') {
// Auto-reject
await $.db.content.update(contentId, { status: 'rejected' })
await notifyUser(content.authorId, 'Content rejected')
return { action: 'auto_rejected' }
}

// Human review needed
const review = await $.human.request({
type: 'content_review',
content,
moderation
})

await $.db.content.update(contentId, { status: review.decision })
return { action: 'human_reviewed', decision: review.decision }
}
export const contentModerationWorkflow = $.workflow('content-moderation', async (contentId: string) => {
  const result = await $.step('moderate', () => moderateContent(contentId))

  return result
})

Parallel Execution

export const dataProcessingWorkflow = $.workflow('data-processing', async (dataId: string) => {
  // Execute multiple steps in parallel
  const [validated, enriched, analyzed] = await Promise.all([
    $.step('validate', () => validateData(dataId)),
    $.step('enrich', () => enrichData(dataId)),
    $.step('analyze', () => analyzeData(dataId)),
  ])

  // Combine results
  const result = await $.step('combine', () => combineResults(validated, enriched, analyzed))

  return result
})

Human-in-the-Loop

export async function reviewProposal(proposalId: string) {
  const proposal = await $.db.proposals.findById(proposalId)

// Request human review
const review = await $.human.request({
type: 'proposal_review',
title: `Review Proposal: ${proposal.title}`,
data: proposal,
assignee: proposal.reviewerId,
timeout: 48 * 60 * 60 * 1000 // 48 hours
})

return review
}
export const approvalWorkflow = $.workflow('approval', async (proposalId: string) => {
  // Create proposal
  await $.step('create', () => createProposal(proposalId))

  // Wait for human review (workflow pauses here)
  const review = await $.step('review', () => reviewProposal(proposalId))

  if (review.approved) {
    await $.step('approve', () => executeProposal(proposalId))
    return { status: 'approved' }
  } else {
    await $.step('reject', () => rejectProposal(proposalId, review.reason))
    return { status: 'rejected', reason: review.reason }
  }
})

Scheduled Workflows

// Run workflow on schedule
export const dailyReportWorkflow = $.workflow('daily-report', async () => {
  const data = await $.step('gather-data', () => gatherMetrics())

  const report = await $.step('generate-report', () => generateReport(data))

  await $.step('send-report', () => emailReport(report))
})

// Schedule it
$.schedule.every('1d', () => dailyReportWorkflow.start())

Event-Driven Workflows

// Trigger workflow from events
$.on('order.created', async (event) => {
  await orderFulfillmentWorkflow.start(event.order.id)
})

$.on('user.signed_up', async (event) => {
  await onboardingWorkflow.start(event.user.id)
})

$.on('payment.failed', async (event) => {
  await paymentRetryWorkflow.start(event.payment.id)
})

Complex Workflow Example

---
title: Content Publishing Pipeline
description: Complete content creation and distribution workflow
---

export async function generateContent(topic: string) {
  return await $.ai.generateText({
    prompt: `Write a comprehensive article about: ${topic}`,
    length: 2000
  })
}

export async function generateImages(content: string) {
  const prompts = extractImageNeeds(content)
  return await $.ai.generateImages({ prompts, style: 'professional' })
}

export async function optimizeForSEO(content: string, images: string[]) {
  return await $.ai.optimize(content, {
    for: 'seo',
    includeImages: images
  })
}

export async function scheduleToSocial(content: ContentData) {
  return await $.social.schedule.posts([
    {
      platform: 'twitter',
      content: generateTweet(content),
      time: 'optimal'
    },
    {
      platform: 'linkedin',
      content: generateLinkedInPost(content),
      time: 'optimal'
    }
  ])
}

export async function publishToWebsite(content: ContentData) {
  return await $.cms.publish({
    title: content.title,
    body: content.body,
    images: content.images,
    status: 'published'
  })

}
export const contentPipelineWorkflow = $.workflow('content-pipeline', async (topic: string) => {
  // Generate content
  const draft = await $.step('generate-content', () => generateContent(topic))

  // Generate images in parallel with SEO optimization
  const [images, metadata] = await Promise.all([
    $.step('generate-images', () => generateImages(draft)),
    $.step('generate-metadata', () => generateSEOMetadata(draft)),
  ])

  // Optimize content
  const optimized = await $.step('optimize-seo', () => optimizeForSEO(draft, images))

  // Human review
  const reviewed = await $.step('human-review', () =>
    $.human.request({
      type: 'content_review',
      content: { ...optimized, images, metadata },
      timeout: 24 * 60 * 60 * 1000,
    })
  )

  if (!reviewed.approved) {
    return { status: 'rejected', reason: reviewed.reason }
  }

  // Publish in parallel
  const [website, social] = await Promise.all([
    $.step('publish-website', () => publishToWebsite(reviewed.content)),
    $.step('schedule-social', () => scheduleToSocial(reviewed.content)),
  ])

  return {
    status: 'published',
    website: website.url,
    social: social.scheduledPosts,
  }
})

Monitoring Workflows

Workflow Status

// Start workflow
const execution = await contentPipelineWorkflow.start('AI in Healthcare')

// Check status
const status = await $.workflow.status(execution.id)
console.log({
  status: status.status, // 'running', 'completed', 'failed'
  currentStep: status.currentStep,
  progress: status.progress,
  startedAt: status.startedAt,
})

// Get history
const history = await $.workflow.history(execution.id)
history.steps.forEach((step) => {
  console.log(`${step.name}: ${step.status} (${step.duration}ms)`)
})

Workflow Metrics

const metrics = await $.workflow.metrics('content-pipeline', {
  period: 'last_30d',
})

console.log({
  totalExecutions: metrics.total,
  successRate: metrics.successRate,
  averageDuration: metrics.avgDuration,
  failureRate: metrics.failureRate,
  retryRate: metrics.retryRate,
})

Error Handling

export const robustWorkflow = $.workflow('robust', async (input) => {
  try {
    await $.step('risky-operation', () => riskyOperation(input), {
      retry: { attempts: 3 },
      timeout: 30000,
    })
  } catch (error) {
    // Handle step failure
    await $.step('handle-error', () => logError(error))

    // Compensate
    await $.step('compensate', () => rollbackChanges(input))

    throw error
  }
})

Deployment Configuration

// do.config.ts
export default {
  workflows: [
    {
      name: 'order-fulfillment',
      source: './workflows/orders.mdx',
      deployment: {
        triggers: ['order.created'],
        timeout: 300000, // 5 minutes
        concurrency: 100,
        retries: {
          enabled: true,
          maxAttempts: 3,
          backoff: 'exponential',
        },
      },
      monitoring: {
        alerts: [
          {
            condition: 'failure_rate > 0.05',
            notify: '[email protected]',
          },
          {
            condition: 'avg_duration > 60000',
            notify: '[email protected]',
          },
        ],
      },
    },
  ],
}

Best Practices

Idempotent Steps

Make steps safe to retry:

export async function createUser(email: string) {
  // Check if already exists
  const existing = await $.db.users.findOne({ email })
  if (existing) {
    return existing // Idempotent
  }

return await $.db.users.create({ email })
}

Proper Error Handling

export async function sendEmail(to: string, subject: string, body: string) {
  try {
    await $.email.send.message({ to, subject, body })
  } catch (error) {
    if (error.code === 'INVALID_EMAIL') {
      // Don't retry invalid emails
      throw new PermanentError('Invalid email address')
    }
    // Retry other errors
    throw error
  }

}

Testing Workflows

import { test } from 'vitest'

test('order fulfillment completes successfully', async () => {
  const orderId = 'test_order_123'

  const result = await orderFulfillmentWorkflow.start(orderId)

  expect(result.status).toBe('completed')
  expect(result.shipmentId).toBeDefined()
})

Production Deployment

Deployment Configuration

// Production workflow deployment
export default {
  workflows: [
    {
      name: 'order-fulfillment',
      source: './workflows/orders.mdx',
      deployment: {
        // Infrastructure
        runtime: 'durable-workflows', // 'durable-workflows' | 'step-functions' | 'temporal'

        // Durability configuration
        durability: {
          enabled: true,
          storage: 'durable-objects',
          checkpointing: {
            enabled: true,
            interval: 10000, // Checkpoint every 10 seconds
            strategy: 'automatic', // 'automatic' | 'manual'
          },
          retention: {
            completed: '7d',
            failed: '30d',
            running: 'indefinite',
          },
        },

        // Execution limits
        limits: {
          timeout: 300000, // 5 minutes max workflow execution
          maxSteps: 100,
          maxRetries: 3,
          concurrency: 1000, // Max concurrent workflow executions
        },

        // Retry configuration
        retry: {
          enabled: true,
          strategy: 'exponential-backoff',
          initialInterval: 1000,
          maxInterval: 60000,
          backoffCoefficient: 2,
          maxAttempts: 3,
        },

        // Idempotency
        idempotency: {
          enabled: true,
          keyGenerator: (input) => `workflow:${input.workflowType}:${input.id}`,
          ttl: 86400, // 24 hours
        },
      },
    },
  ],
}

Health & Status Monitoring

// Workflow health check
export async function workflowHealthCheck() {
  const checks = {
    executor: await checkWorkflowExecutor(),
    storage: await checkWorkflowStorage(),
    queue: await checkWorkflowQueue(),
  }

  return {
    healthy: Object.values(checks).every(c => c.healthy),
    checks,
    timestamp: new Date().toISOString(),
  }
}

async function checkWorkflowExecutor() {
  try {
    // Check if workflow executor is responsive
    const testWorkflow = await $.workflow.test('health-check', async () => ({
      status: 'ok',
    }))

    await testWorkflow.start()
    const result = await testWorkflow.wait(5000)

    return {
      healthy: result?.status === 'ok',
      latency: Date.now() - testWorkflow.startedAt,
    }
  } catch (error) {
    return {
      healthy: false,
      error: error.message,
    }
  }
}

async function checkWorkflowStorage() {
  try {
    // Verify durable storage is accessible
    await $.durableObjects.ping()
    return { healthy: true }
  } catch (error) {
    return { healthy: false, error: error.message }
  }
}

async function checkWorkflowQueue() {
  try {
    const metrics = await $.workflow.queue.metrics()
    return {
      healthy: metrics.backlog < 10000,
      backlog: metrics.backlog,
      processing: metrics.processing,
    }
  } catch (error) {
    return { healthy: false, error: error.message }
  }
}

Workflow Observability

export default {
  workflows: [
    {
      name: 'production-workflow',
      monitoring: {
        // Metrics
        metrics: {
          enabled: true,
          metrics: [
            'workflow_executions_total',
            'workflow_duration_seconds',
            'workflow_steps_total',
            'workflow_retries_total',
            'workflow_failures_total',
            'workflow_success_rate',
            'workflow_backlog_size',
          ],
          labels: ['workflow_name', 'status', 'step_name'],
        },

        // Distributed tracing
        tracing: {
          enabled: true,
          traceEachStep: true,
          includeInputOutput: false, // Don't log sensitive data
          sampleRate: 1.0,
        },

        // Logging
        logging: {
          level: 'info',
          structuredLogs: true,
          logEachStep: true,
          includeStackTrace: true,
          redactFields: ['password', 'token', 'apiKey'],
        },

        // Workflow visualization
        visualization: {
          enabled: true,
          endpoint: '/workflows/visualize',
          realtime: true,
        },

        // Alerting
        alerts: [
          {
            name: 'high-failure-rate',
            condition: 'workflow_failures_total / workflow_executions_total > 0.05',
            duration: '10m',
            severity: 'critical',
            notify: ['[email protected]'],
          },
          {
            name: 'workflow-stuck',
            condition: 'workflow_duration_seconds{status="running"} > 3600',
            severity: 'warning',
            notify: ['[email protected]'],
          },
          {
            name: 'large-backlog',
            condition: 'workflow_backlog_size > 1000',
            severity: 'warning',
            notify: ['[email protected]'],
            actions: ['scale-up'],
          },
        ],
      },
    },
  ],
}

CI/CD for Workflows

# .github/workflows/deploy-workflows.yml
name: Deploy Workflows to Production

on:
  push:
    branches: [main]
    paths:
      - 'workflows/**'
      - 'package.json'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v2

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Unit tests
        run: pnpm test workflows/

      - name: Integration tests
        run: pnpm test:integration:workflows

      - name: Workflow simulation
        run: pnpm test:simulate-workflows

      - name: Chaos testing
        run: pnpm test:chaos:workflows

  deploy-staging:
    needs: test
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4

      - name: Deploy workflows
        run: pnpm do deploy:workflows --env staging
        env:
          DO_TOKEN: ${{ secrets.DO_STAGING_TOKEN }}

      - name: Verify deployment
        run: |
          # Check workflow health
          curl --fail https://staging.example.do/workflows/health

          # Run test workflow
          pnpm do workflow:test --env staging

      - name: Run E2E workflow tests
        run: pnpm test:e2e:workflows --env staging

  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4

      - name: Deploy with blue-green strategy
        run: |
          # Deploy to green slot
          pnpm do deploy:workflows \
            --env production \
            --slot green \
            --version ${{ github.sha }}
        env:
          DO_TOKEN: ${{ secrets.DO_PRODUCTION_TOKEN }}

      - name: Migrate in-flight workflows
        run: |
          # Gracefully migrate running workflows to new version
          pnpm do workflows:migrate \
            --from blue \
            --to green \
            --timeout 600

      - name: Switch traffic
        run: pnpm do switch-slot --from blue --to green

      - name: Monitor for 5 minutes
        run: |
          pnpm do monitor-workflows \
            --duration 300 \
            --error-threshold 0.01

      - name: Verify production
        run: |
          curl --fail https://api.example.do/workflows/health
          pnpm do workflows:verify --env production

      - name: Notify deployment
        uses: slackapi/slack-github-action@v1
        with:
          payload: |
            {
              "text": "✅ Workflows deployed to production",
              "version": "${{ github.sha }}"
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

Workflow State Management

// Durable workflow state
export const orderFulfillmentWorkflow = $.workflow(
  'order-fulfillment',
  async (orderId: string, ctx: WorkflowContext) => {
    // State is automatically persisted between steps
    const state = {
      orderId,
      status: 'pending',
      steps: [],
    }

    try {
      // Step 1: Validate payment
      state.status = 'validating-payment'
      await ctx.checkpoint(state) // Manual checkpoint

      const payment = await ctx.step('validate-payment', async () => {
        return await validatePayment(orderId)
      })

      state.steps.push({ name: 'payment', status: 'completed', payment })

      // Step 2: Reserve inventory
      state.status = 'reserving-inventory'
      await ctx.checkpoint(state)

      const inventory = await ctx.step('reserve-inventory', async () => {
        return await reserveInventory(orderId)
      })

      state.steps.push({ name: 'inventory', status: 'completed', inventory })

      // Step 3: Create shipment
      state.status = 'creating-shipment'
      const shipment = await ctx.step('create-shipment', async () => {
        return await createShipment(orderId)
      })

      state.steps.push({ name: 'shipment', status: 'completed', shipment })

      // Final state
      state.status = 'completed'
      await ctx.checkpoint(state)

      return state
    } catch (error) {
      // Save error state
      state.status = 'failed'
      state.error = error.message
      await ctx.checkpoint(state)

      throw error
    }
  }
)

// Workflow recovery
export async function recoverWorkflow(workflowId: string) {
  // Get workflow state from durable storage
  const state = await $.workflow.getState(workflowId)

  if (!state) {
    throw new Error('Workflow not found')
  }

  // Resume from last checkpoint
  return await $.workflow.resume(workflowId, {
    fromCheckpoint: state.lastCheckpoint,
    retryFailedSteps: true,
  })
}

Workflow Scaling

export default {
  workflows: [
    {
      name: 'production-workflow',
      scaling: {
        // Auto-scaling configuration
        auto: {
          enabled: true,
          minInstances: 2,
          maxInstances: 20,

          // Scale based on queue depth
          queueDepth: {
            target: 100,
            scaleUpThreshold: 200,
            scaleDownThreshold: 50,
          },

          // Scale based on processing time
          processingTime: {
            target: 5000, // 5 seconds
            scaleUpThreshold: 10000,
          },

          // Cooldown periods
          cooldown: {
            scaleUp: 60, // seconds
            scaleDown: 300,
          },
        },

        // Manual scaling
        manual: {
          instances: 5,
        },

        // Schedule-based scaling
        scheduled: [
          {
            schedule: '0 9 * * 1-5', // Weekdays at 9 AM
            instances: 10,
          },
          {
            schedule: '0 18 * * 1-5', // Weekdays at 6 PM
            instances: 3,
          },
        ],
      },
    },
  ],
}

Workflow Error Handling & Recovery

// Advanced error handling
export const resilientWorkflow = $.workflow('resilient', async (input, ctx) => {
  // Retry with exponential backoff
  await ctx.step(
    'risky-operation',
    async () => {
      return await riskyOperation(input)
    },
    {
      retry: {
        maxAttempts: 5,
        backoff: 'exponential',
        initialInterval: 1000,
        maxInterval: 30000,
        retryableErrors: ['NetworkError', 'TimeoutError'],
      },
      timeout: 60000,
    }
  )

  // Compensating transactions
  try {
    await ctx.step('create-order', () => createOrder(input))
    await ctx.step('charge-payment', () => chargePayment(input))
    await ctx.step('send-confirmation', () => sendConfirmation(input))
  } catch (error) {
    // Rollback on failure
    await ctx.compensate(async () => {
      await cancelOrder(input.orderId)
      await refundPayment(input.paymentId)
    })

    throw error
  }

  // Circuit breaker pattern
  await ctx.step(
    'external-api-call',
    async () => {
      return await externalAPI.call(input)
    },
    {
      circuitBreaker: {
        enabled: true,
        errorThreshold: 50, // % errors to open circuit
        timeout: 30000,
        resetTimeout: 60000,
      },
    }
  )

  // Saga pattern
  const saga = ctx.saga()

  try {
    const reservation = await saga.step('reserve-inventory', reserveInventory)
    saga.compensate('reserve-inventory', () => releaseInventory(reservation.id))

    const payment = await saga.step('process-payment', processPayment)
    saga.compensate('process-payment', () => refundPayment(payment.id))

    const shipment = await saga.step('create-shipment', createShipment)
    saga.compensate('create-shipment', () => cancelShipment(shipment.id))

    await saga.commit()
  } catch (error) {
    await saga.rollback()
    throw error
  }
})

Workflow Testing

import { test, describe, expect } from 'vitest'

describe('Order Fulfillment Workflow', () => {
  test('successful order flow', async () => {
    const workflow = await orderFulfillmentWorkflow.test()

    const result = await workflow.execute('order-123', {
      mock: {
        'validate-payment': { valid: true, amount: 100 },
        'reserve-inventory': { reserved: true },
        'create-shipment': { trackingNumber: 'TRACK-123' },
      },
    })

    expect(result.status).toBe('completed')
    expect(result.steps).toHaveLength(3)
  })

  test('handles payment failure', async () => {
    const workflow = await orderFulfillmentWorkflow.test()

    await expect(
      workflow.execute('order-456', {
        mock: {
          'validate-payment': new Error('Payment failed'),
        },
      })
    ).rejects.toThrow('Payment failed')

    // Verify workflow state
    const state = await workflow.getState()
    expect(state.status).toBe('failed')
    expect(state.steps[0].name).toBe('payment')
  })

  test('workflow recovery from checkpoint', async () => {
    const workflow1 = await orderFulfillmentWorkflow.test()

    // Start workflow
    const promise = workflow1.execute('order-789')

    // Simulate crash after first step
    await workflow1.stopAfterStep('validate-payment')

    // Resume workflow
    const workflow2 = await orderFulfillmentWorkflow.test()
    const result = await workflow2.resume(workflow1.id)

    expect(result.status).toBe('completed')
  })

  test('workflow timeout handling', async () => {
    const workflow = await orderFulfillmentWorkflow.test({
      timeout: 1000,
    })

    await expect(
      workflow.execute('order-slow', {
        mock: {
          'validate-payment': async () => {
            await new Promise(resolve => setTimeout(resolve, 2000))
            return { valid: true }
          },
        },
      })
    ).rejects.toThrow('Workflow timeout')
  })

  test('concurrent workflow executions', async () => {
    const workflows = Array.from({ length: 10 }, (_, i) =>
      orderFulfillmentWorkflow.test().then(w => w.execute(`order-${i}`))
    )

    const results = await Promise.all(workflows)
    expect(results).toHaveLength(10)
    expect(results.every(r => r.status === 'completed')).toBe(true)
  })
})

Production Troubleshooting

# View running workflows
pnpm do workflows list --status running

# Output:
# ID              STATUS    STEP              DURATION  RETRIES
# wf_abc123       running   create-shipment   45s       0
# wf_def456       running   validate-payment  120s      2
# wf_ghi789       pending   -                 0s        0

# Inspect specific workflow
pnpm do workflow inspect wf_abc123

# Output:
# Workflow: wf_abc123
# Type: order-fulfillment
# Status: running
# Started: 2024-01-15 10:30:00
# Duration: 45s
#
# Steps:
#  ✓ validate-payment (completed in 2.3s)
#  ✓ reserve-inventory (completed in 1.8s)
#  ⟳ create-shipment (in progress, 45s)
#
# State:
#  orderId: order-123
#  paymentId: pay_456
#  inventoryReservation: inv_789

# View workflow logs
pnpm do workflow logs wf_abc123 --follow

# Retry failed workflow
pnpm do workflow retry wf_failed123

# Cancel stuck workflow
pnpm do workflow cancel wf_stuck456

# View workflow metrics
pnpm do workflow metrics --period 24h

# Output:
# Workflows (last 24h):
# Total executions: 15,234
# Successful: 14,890 (97.7%)
# Failed: 344 (2.3%)
# Average duration: 12.5s
# P95 duration: 45.2s
# P99 duration: 120.8s

# Debug workflow execution
pnpm do workflow debug wf_abc123 --verbose

# Export workflow state
pnpm do workflow export wf_abc123 > workflow-state.json

# Replay workflow with modifications
pnpm do workflow replay wf_abc123 \
  --modify-state workflow-state-fixed.json

Workflow Performance Optimization

export default {
  workflows: [
    {
      name: 'high-performance-workflow',
      performance: {
        // Parallel execution
        parallel: {
          enabled: true,
          maxConcurrency: 10,
          failFast: false,
        },

        // Step batching
        batching: {
          enabled: true,
          batchSize: 50,
          maxWaitTime: 100, // ms
        },

        // Caching
        cache: {
          enabled: true,
          ttl: 300,
          keyPrefix: 'workflow:',
          cacheSteps: ['fetch-user-data', 'fetch-product-catalog'],
        },

        // Resource management
        resources: {
          memory: '512MB',
          cpu: '0.5', // 50% of 1 CPU
          timeout: 300000,
          maxQueueTime: 60000,
        },

        // Checkpointing optimization
        checkpointing: {
          strategy: 'adaptive', // Checkpoint based on complexity
          minInterval: 5000,
          maxInterval: 60000,
          costThreshold: 0.01, // Checkpoint if next step costs > 1 cent
        },
      },
    },
  ],
}
    • Workflows Framework - Complete workflow capabilities
    • Functions - Function composition
  • Agents - Deploy as agents
  • Services - Deploy as services
  • Configuration - Deployment configuration
  • Build Process - Build pipeline