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

