Tony Yun

    Tony Yun

    11 months ago
    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.
    Michael Adkins

    Michael Adkins

    11 months ago
    Tony Yun

    Tony Yun

    11 months ago
    thanks @Michael Adkins!
    Michael Adkins

    Michael Adkins

    11 months ago
    (You can get your current flow run id from
    prefect.context["flow_run_id"]
    inside a task)
    Tony Yun

    Tony Yun

    11 months ago
    That’s exactly what i’m going to ask!! thanks!!
    oh I just looked at the
    State
    class, there seems no
    is_cancelled
    state 😢
    Michael Adkins

    Michael Adkins

    11 months ago
    You can do
    isinstance(flow_run_view.state, prefect.states.Cancelled)
    Tony Yun

    Tony Yun

    11 months ago
    great, thanks!
    Michael Adkins

    Michael Adkins

    11 months ago
    Or
    flow_run_view.state.is_finished() and not (flow_run_view.state.is_failed() or flow_run_view.state.is_successful())
    Tony Yun

    Tony Yun

    11 months ago
    i like the first one more. elegant
    Michael Adkins

    Michael Adkins

    11 months ago
    Or contribute a
    is_cancelled
    check to
    State
    on Github 😄
    Tony Yun

    Tony Yun

    11 months ago
    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 :
    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
    Michael Adkins

    Michael Adkins

    11 months ago
    It works fine for me 😄
    Hmm..
    Can you
    import prefect
    and
    print(prefect.__version__)
    in that same environment?
    Tony Yun

    Tony Yun

    11 months ago
    actually it runs fine in python console, but wrong in registering
    it failed at the health check step while registering:
    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'
    Michael Adkins

    Michael Adkins

    11 months ago
    Seems like you've got an environment issue. Are you registering with the CLI or Python?
    Tony Yun

    Tony Yun

    11 months ago
    CLI
    Michael Adkins

    Michael Adkins

    11 months ago
    Is that
    prefect version
    different?
    Tony Yun

    Tony Yun

    11 months ago
    same, I installed 0.15.5 in my venv
    Michael Adkins

    Michael Adkins

    11 months ago
    What storage are you using?
    Tony Yun

    Tony Yun

    11 months ago
    oh.. that’s why:
    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!!
    Michael Adkins

    Michael Adkins

    11 months ago
    👍