Polling Conditions ๐Ÿ”„

Master the art of handling long-running tasks! Learn how to make your workflow wait for operations to complete.

View Complete Polling Conditions Schema

Common Polling Examples

Here are some typical polling conditions you might use:

// Wait for a job to complete
conditions: {
  pollUntil: ["{{ status = 'completed' }}"]
}

Real World Example ๐ŸŒŸ

Here's a common scenario where polling is essential - processing a large dataset:

import { GraphCompose } from '@graph-compose/client';

const workflow = new GraphCompose()
  // ๐Ÿš€ Step 1: Start the data processing job
  .node('start_job')
    .post('http://api.example.com/jobs')
    .withBody({
      type: 'process_data'
    })
  .end()

  // ๐Ÿ”„ Step 2: Poll the job status until it's complete
  .node('check_status')
    .withDependencies(['start_job'])
    .get('http://api.example.com/jobs/{{results.start_job.jobId}}')
    // โฑ๏ธ Step 3: The retry policy controls how often we check
    .withRetries({
       initialInterval: '1 second',
       maximumAttempts: 3,
       maximumInterval: '1 second'
    })
    .withConditions({
      pollUntil: ["{{ status = 'completed' }}"] // Wait until status is 'completed'
    })
  .end();
  // ๐Ÿ’ก Step 4: Workflow continues automatically after 'check_status' completes

How It Works ๐Ÿ”ง

Polling is simple but powerful:

  1. Make an HTTP request
  2. Check if pollUntil condition is true
  3. If true โ†’ continue workflow
  4. If false โ†’ retry based on retry policy
  5. Repeat until success or max attempts reached

Advanced Usage ๐Ÿš€

Combining with Flow Control

You can combine polling with Flow Control for complex scenarios:

{
  "id": "check_status",
  "type": "http",
  "conditions": {
    "pollUntil": ["{{ status != 'in_progress' }}"],
    "terminateWhen": ["{{ status = 'failed' }}"],
    "continueTo": [
      {
        "to": "process_results",
        "when": "{{ status = 'completed' }}"
      }
    ]
  }
}

This setup:

  1. ๐Ÿ”„ Polls until status changes from 'in_progress'
  2. ๐Ÿ›‘ Terminates if status is 'failed'
  3. โœจ Continues to process results if completed