https://prefect.io logo
#prefect-community
Title
# prefect-community
d

David Haynes

04/27/2022, 8:20 PM
Hey folks. If I register a flow, I get an identifier back. How do I use that identifier to get the flow state information back from the service? I am probably just looking in the wrong place, but I can't find it in the docs.
k

Kevin Kho

04/27/2022, 8:27 PM
What information are you looking for specifically?
d

David Haynes

04/27/2022, 8:30 PM
Like the state returned from flow.run(), specifically the success/fail of the flow and, optionally, the success/fail of the tasks in the flow.
k

Kevin Kho

04/27/2022, 8:31 PM
So there is a distinction between the flow id and flow run id. The flow id is the one you register, and one flow id corresponds to multiple runs so you want the flow run id. You would need to hit the GraphQL API to fetch the information. Could you tell me though what the intention is? Are you looking for this to run after every Flow to get an alert? Are you only interested in Failure?
d

David Haynes

04/27/2022, 8:33 PM
Right now, the use case is a flow with tasks a, b and c. Let's say, task b raises an exception. Is there some way to query the server to ask 'Did that flow succeed or fail?'
I guess that would be the flow run id. I'm not sure how to get that from a registered flow either.
BTW 1.0 not Orion.
You know what? Never mind. I think using a state handler will do everything I need. Thanks for helping.
k

Kevin Kho

04/27/2022, 8:41 PM
Ok I am in the middle of typing a query but let me list the options: 1. State handlers -> the flow will report itself if a task succeeds or fails 2. Automations -> Prefect Cloud sees something failed then sends a message 3. Your own query after the flow runs (am working on an example)
Copy code
query {
  flow (where: {id: {_eq: "2c5a1658-8b21-4d4e-924a-e9e4f5e56786"}}) {
    id
    name
    flow_runs (order_by: {start_time:desc},
               limit:1){
      id
      name
      start_time
    }
  }
}
This query gets the latest flow run for a given flow id. And then with that flow_run you can query the state of the task runs
d

David Haynes

04/27/2022, 8:46 PM
Thanks. That may come in useful in my next flow.
a

Anna Geller

04/27/2022, 9:21 PM
Is there some way to query the server to ask 'Did that flow succeed or fail?'
You could also answer those questions by going to the UI - it might be easier that way
d

David Haynes

04/27/2022, 10:01 PM
I don't think the UI would help in this case since I need the values programmatically.
👍 1
k

Kevin Kho

04/27/2022, 10:03 PM
Yeah the state handler will be easier because you can just use
prefect.context.flow_run_id
5 Views