等待使用轮询

sys.sleep 标准库函数会在指定的秒数内暂停执行,最长持续 31536000(一年)。

暂停工作流

您可以通过向工作流的定义添加休眠步骤来暂停工作流的执行。此步骤包含对 sys.sleep 的调用,并指定您希望暂停工作流的时长(以秒为单位):

YAML

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

JSON

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

轮询数据

您还可以使用 sys.sleep 来轮询给定时间间隔内的数据。例如,您可能希望轮询 API 直到满足特定条件:

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"
          }
        }
      ]
    }
  }