Hi, I'm trying to get the next scheduled retry tas...
# prefect-community
j
Hi, I'm trying to get the next scheduled retry task through prefect.context.scheduled_start_time. I expected it would be something like shown in the INFO log. e.g. "[2019-08-20 015921,499] INFO - prefect.Flow | Waiting for next available Task run at 2019-08-20T015931.428285+00:00". Obviously, herein the retry task is scheduled to run in 10 seconds later. However, prefect.context.scheduled_start_time just gave me a now() time. How can I get the time info regarding when the next retry takes place?
j
Hi James, additional information about scheduled states is generally only available when Prefect is backed by a database + API like Prefect Cloud. When calling
flow.run()
in Core, we’re running a “lite” in-process scheduler, but it doesn’t have access to all the details of the scheduled states. Therefore context fields like
scheduled_start_time
fall back to their default values (
now()
).
However,
scheduled_start_time
sounds like it might not be what you’re interested in.
scheduled_start_time
tells you what time the current run was supposed to start (for example, if it was scheduled for 9:00am, but actually starts at 90001,
scheduled_start_time=9:00
but
start_time=9:00:01
). Sounds like you’re looking for information about the next (future) run?
For that you’ll need to introspect the states that result from running your flow, and see if any of them are scheduled. (
[state for state in run_states if state.is_scheduled() ]
). Scheduled states have a
start_time
attribute that tells you when they are eligible to run again
j
Thank you, Jeremiah. I'd look into that direction.