Wait using polling

The sys.sleep standard library function suspends execution for the given number of seconds to a maximum of 31536000 (one year).

Pause a workflow

You can pause the execution of a workflow by adding a sleep step to your workflow's definition. This step includes a call to sys.sleep and specifies in seconds how long you want to pause the workflow:

YAML

  - STEP_NAME:
      call: sys.sleep
      args:
          seconds: SLEEP_IN_SECONDS
    

JSON

    [
      {
        "STEP_NAME": {
          "call": "sys.sleep",
          "args": {
            "seconds": "SLEEP_IN_SECONDS"
          }
        }
      }
    ]
    

Poll for data

You can also use sys.sleep to poll for data over a given interval. For example, you might want to poll an API until a specific condition is met:

YAML

  main:
      params: [jobId]
      steps:
        - checkJob:
            call: http.get
            args:
                url: ${"https://example.com/jobs/" + jobId}
                auth:
                    type: OAuth2
            result: jobStatus
        - checkIfDone:
            switch:
              - condition: ${jobStatus.complete}
                return: ${jobStatus}
        - wait:
            call: sys.sleep
            args:
                seconds: 60
            next: checkJob
    

JSON

  {
    "main": {
      "params": [
        "jobId"
      ],
      "steps": [
        {
          "checkJob": {
            "call": "http.get",
            "args": {
              "url": "${\"https://example.com/jobs/\" + jobId}",
              "auth": {
                "type": "OAuth2"
              }
            },
            "result": "jobStatus"
          }
        },
        {
          "checkIfDone": {
            "switch": [
              {
                "condition": "${jobStatus.complete}",
                "return": "${jobStatus}"
              }
            ]
          }
        },
        {
          "wait": {
            "call": "sys.sleep",
            "args": {
              "seconds": 60
            },
            "next": "checkJob"
          }
        }
      ]
    }
  }
    

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.