hi, does anyone know how to get the flow running s...
# ask-community
t
hi, does anyone know how to get the flow running status inside a task? I need make some logics for different status like cancelled, running, etc.
z
t
thanks @Zanie!
z
(You can get your current flow run id from
prefect.context["flow_run_id"]
inside a task)
t
That’s exactly what i’m going to ask!! thanks!!
oh I just looked at the
State
class, there seems no
is_cancelled
state 😢
z
You can do
isinstance(flow_run_view.state, prefect.states.Cancelled)
t
great, thanks!
z
Or
flow_run_view.state.is_finished() and not (flow_run_view.state.is_failed() or flow_run_view.state.is_successful())
t
i like the first one more. elegant
z
Or contribute a
is_cancelled
check to
State
on Github 😄
😄 1
t
one major Q from this, if the flow is cancelled, is the task within the flow still be able to process the logics for
if cancelled, do X
?..
or have to be handled in a
try: X, except Y, finally Z
way
nevermind I’ll try it out
hmm, see this error while using :
Copy code
from prefect.backend import FlowRunView

ModuleNotFoundError: No module named 'prefect.backend'
I’m using Prefect==0.15.5
not work in the latest version 0.15.7 either
z
It works fine for me 😄
Hmm..
Can you
import prefect
and
print(prefect.__version__)
in that same environment?
t
actually it runs fine in python console, but wrong in registering
it failed at the health check step while registering:
Copy code
Beginning health checks...
System Version check: OK
Traceback (most recent call last):
  File "/opt/prefect/healthcheck.py", line 152, in <module>
    flows = cloudpickle_deserialization_check(flow_file_paths)
  File "/opt/prefect/healthcheck.py", line 44, in cloudpickle_deserialization_check
    flows.append(cloudpickle.loads(flow_bytes))
ModuleNotFoundError: No module named 'prefect.backend'
z
Seems like you've got an environment issue. Are you registering with the CLI or Python?
t
CLI
z
Is that
prefect version
different?
t
same, I installed 0.15.5 in my venv
z
What storage are you using?
t
oh.. that’s why:
Copy code
storage = Docker(
    base_image="prefecthq/prefect:0.14.9-python3.7",
hmm, i thought it will give me prefect version not match error. but anyway, let me try upgrade that one
works now. Thanks!!
z
👍