I know I can get the actual time the flow was ente...
# prefect-cloud
a
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
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:
Copy code
@flow
def my_flow(x: datetime = None):
    if x is None:
        x = prefect.runtime.flow_run.scheduled_start_time
a
ahhhh ok. I had found
Copy code
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
scheduled start time is exactly equivalent to your example (https://github.com/PrefectHQ/prefect/blob/main/src/prefect/runtime/flow_run.py#L125)
a
you are right, my mistake. I was comparing an auto-scheduled run to a manually triggered one.
👍 1
c
no worries!
a
@Chris White, should I expect
Copy code
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}