https://prefect.io logo
Title
a

Andy Dienes

04/13/2023, 2:53 PM
I know I can get the actual time the flow was entered with
prefect.context.get_run_context().start_time
, but that seems a little dangerous if the run is late; I'd rather pull the scheduled time if possible
1
c

Chris White

04/13/2023, 4:01 PM
Hi Andy; if you put your deployment on a schedule, then the parameters will end up being either their default values or the values you set as default on the deployment. You can use
prefect.runtime
to access contextual information such as scheduled start time, so here's the pattern I recommend:
@flow
def my_flow(x: datetime = None):
    if x is None:
        x = prefect.runtime.flow_run.scheduled_start_time
a

Andy Dienes

04/13/2023, 4:08 PM
ahhhh ok. I had found
ctx = prefect.context.get_run_context()
ctx.flow_run.expected_start_time
but yours seems cleaner, thanks
👍 1
@Chris White actually, it appears
prefect.runtime.flow_run.scheduled_start_time
gives the actual time that the job was scheduled. I'm looking for more the "logical" time, so if my schedule is a
* * * *
cron, then this time will always be exactly on the minute. is there a way to get this besides my earlier pattern?
c

Chris White

04/13/2023, 6:26 PM
scheduled start time is exactly equivalent to your example (https://github.com/PrefectHQ/prefect/blob/main/src/prefect/runtime/flow_run.py#L125)
a

Andy Dienes

04/13/2023, 6:39 PM
you are right, my mistake. I was comparing an auto-scheduled run to a manually triggered one.
👍 1
c

Chris White

04/13/2023, 6:40 PM
no worries!
a

Andy Dienes

04/13/2023, 9:03 PM
@Chris White, should I expect
prefect.cli.deployment.pause_schedule(prefect.runtime.deployment.name)
to pause the deployment associated with that flow run? I'm not sure how to call this correctly, but this had seemed to be the way
ah. I need to prepend the flow name with
myflowname/{prefect.runtime.deployment.name}