https://prefect.io logo
Title
d

Dominik Wagner

07/26/2022, 1:28 PM
Prefect 2.0 | Accessing current flow state Hi! 👋 Possibly simple question which I can’t seem to find an answer for: Can I access the state of the current flow from within that flow? In particular I’d like to check if the flow is retrying, and if so pass an extra argument to my task(s) i.e.
@flow
def my_flow():
  if <somehow_get_state_of_this_flow?> == "Retrying":
    do_something()
1
a

Anna Geller

07/26/2022, 1:32 PM
when running tasks, you can do:
if task.get_state().is_failed():
or rather:
if task.get_state().is_retrying():
this assumes that task is submitted to task runner
@task
def do_sth():
   ...

@flow
def my_flow():
  if do_sth.submit().get_state().is_retrying():
    do_something()
d

Dominik Wagner

07/26/2022, 1:37 PM
Thanks, but maybe it wasn’t clear, I’m retrying the flow, not a task (added in 2.0b8). All my tasks are using
shell_run_command()
from
prefect_shell
, and I don’t think I can add retries there?
a

Anna Geller

07/26/2022, 1:38 PM
for flow there is no way currently, but will be after GA release
:party-parrot: 1
d

Dominik Wagner

07/26/2022, 1:41 PM
Okay, thanks! Will hold off until tomorrow then 😁
:thank-you: 1
🙌 1