Movatterモバイル変換


[0]ホーム

URL:


Usepd.flow.delay todelay a step in a workflow.These docs show you how to write Python code to handle delays. If you don’t need to write code, seeour built-in delay actions.

Usingpd.flow.delay

pd.flow.delay takes one argument: the number ofmilliseconds you’d like to pause your workflow until the next step executes. .Note thatdelays happen at the end of the step where they’re called.
import randomdef handler(pd:'pipedream'):    # Delay a workflow for 60 seconds (60,000 ms)    pd.flow.delay(60 * 1000)    # Delay a workflow for 15 minutes    pd.flow.delay(15 * 60 * 1000)    # Delay a workflow based on the value of incoming event data,    # or default to 60 seconds if that variable is undefined    default= 60 * 1000    delayMs= pd.steps["trigger"].get("event", {}).get("body", {}).get("delayMs", default)    pd.flow.delay(delayMs)    # Delay a workflow a random amount of time    pd.flow.delay(random.randint(0,999))
Paused workflow stateWhenpd.flow.delay is executed in a Python step, the workflow itself will enter aPaused state.While the workflow is paused, it will not incur any credits towards compute time. You can alsoview all paused workflows in the Event History.

Credit usage

The length of time a workflow is delayed frompd.flow.delay doesnot impact your credit usage. For example, delaying a 256 megabyte workflow for five minutes willnot incur ten credits.However, usingpd.flow.delay in a workflow will incur two credits.One credit is used to initially start the workflow, then the second credit is used when the workflow resumes after its pause period has ended.
Exact credit usage depends on duration and memory configurationIf your workflow’sexecution timeout limit is set to longer thandefault limit, it may incur more than twocredits when usingpd.flow.delay.

cancel_url andresume_url

Both the built-inDelay actions andpd.flow.delay return acancel_url andresume_url that lets you cancel or resume paused executions.These URLs are specific to a single execution of your workflow. While the workflow is paused, you can load these in your browser or send an HTTP request to either:
  • Hitting thecancel_url will immediately cancel that execution
  • Hitting theresume_url will immediately resume that execution early
Since Pipedream pauses your workflow at theend of the step where you run callpd.flow.delay, you can send these URLs to third party systems, via email, or anywhere else you’d like to control the execution of your workflow.
import requestsdef handler(pd:'pipedream'):  links= pd.flow.delay(15 * 60 * 1000)  # links contains a dictionary with two entries: resume_url and cancel_url  # Send the URLs to a system you own  requests.post("https://example.com",json=links)  # Email yourself the URLs. Click on the links to cancel / resume  pd.send.email(    subject=f"Workflow execution{pd.steps['trigger']['context']['id']}",    text=f"Cancel your workflow here:{links['cancel_url']} . Resume early here:{links['resume_url']}",    html=None  )  # Delay happens at the end of this step
Inpd.send.email, thehtml argument defaults to"", so it overrides the emailtext unless explicitly set toNone.

When delays happen

Pipedream pauses your workflow at theend of the step where you callpd.flow.delay. This lets you send thecancel_url andresume_url to third-party systems.
def handler(pd:'pipedream'):  urls= pd.flow.delay(15 * 60 * 1000)  cancel_url, resume_url= urls["cancel_url"], urls["resume_url"]  # ... run any code you want here  # Delay happens at the end of this step

Delays and HTTP responses

You cannot runpd.respond after runningpd.flow.delay. Pipedream ends the original execution of the workflow whenpd.flow.delay is called and issues the following response to the client to indicate this state:
$.respond() not called for this invocation
If you need to set a delay on an HTTP request triggered workflow, consider usingtime.sleep instead.

time.sleep

Alternatively, you can usetime.sleep instead of usingpd.flow.delay to delay individual workflow steps.However, there are some drawbacks to usingtime.sleep instead ofpd.flow.delay.time.sleep will count towards your workflow’s compute time, for example:
import timedef handler(pd:'pipedream'):  # delay this step for 30 seconds  delay= 30  time.sleep(delay)
The Python step above will hold the workflow’s execution for this step for 30 seconds; however, 30 seconds will alsocontribute to your credit usage. Also consider that workflows have a hard limit of seconds.

[8]ページ先頭

©2009-2025 Movatter.jp