sleep

Pause pipeline execution for a specified duration with optional random addition

sleep

Pauses pipeline execution for a specified duration with optional random addition.

Syntax

sleep <duration>;
sleep <duration> <random>;

Parameters

  • <duration> - Base time to pause execution. Accepts duration units such as:

    • 1s - 1 second
    • 500ms - 500 milliseconds
    • 2m - 2 minutes
    • 100 - 100 milliseconds (bare numbers are interpreted as milliseconds)
  • <random> - When specified, adds a random duration between 0 and <random> (inclusive) to the base <duration>. The actual sleep time will be duration + random(0, random). Accepts the same duration units.

Description

The sleep action pauses the execution of the current pipeline for the specified duration. This is useful for example in various testing scenarios, rate limiting and retry logic.

When a random parameter is specified, the action adds a random amount of time (between 0 and the random value) to the base duration each time it executes. This is useful for:

  • Adding jitter to retry logic to prevent thundering herd problems
  • Simulating variable network latency in tests
  • Load testing with realistic timing variations

The sleep action does not modify the request or response and passes through the previous pipeline result unchanged.

Examples

Basic sleep with seconds

sleep 1s;

Sleep with milliseconds

sleep 500ms;

Sleep with random jitter

# Sleep for 100ms plus a random amount up to 400ms
# Actual sleep time will be between 100ms and 500ms
sleep 100ms 400ms;

Retry logic with exponential backoff and jitter

try {
    backend "MY_BACKEND";
} catch {
    # Base delay of 1s with up to 2s random jitter
    # Actual sleep: 1s to 3s
    sleep 1s 2s;
    backend "MY_BACKUP_BACKEND";
}

Error handling with fixed sleep

try {
    backend "MY_BACKEND";
} catch {
    sleep 2s;
    backend "MY_BACKUP_BACKEND";
}

Notes

  • The sleep operation is non-blocking at the system level - it does not block OS threads
  • Other requests and connections continue processing during sleep
  • Sleep keeps the request context in memory; consider alternative designs for delays longer than a few minutes
  • Bare numbers without units are interpreted as milliseconds for backward compatibility
  • A sleep duration of zero (sleep 0s;) does not sleep - it continues execution immediately

See Also