폴링을 사용하여 대기

sys.sleep 표준 라이브러리 함수는 지정된 시간(초) 동안 최대 31,536,000(1년)까지 실행을 정지합니다.

워크플로 일시중지

워크플로 정의에 절전 단계를 추가하여 워크플로 실행을 일시중지할 수 있습니다. 이 단계에는 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

  waitForJobCompletion:
      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

  {
    "waitForJobCompletion": {
      "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"
          }
        }
      ]
    }
  }