https://prefect.io logo
s

Samuel Tober

08/17/2021, 8:46 AM
Hey! Is there a way to get no. successful runs of a certain flow during the execution of the flow? I want to build a state handler that outputs no. successful runs
k

Kevin Kho

08/17/2021, 2:00 PM
Hey @Samuel Tober, you mean the number successful task runs? You could have to use a state handler at the Flow level that queries the graphQL API for the task and their states
Copy code
def get_flow_run(flow_run_id: str) -> PrefectFlowRun:
    client = Client()
    response = client.graphql(
        f"""
        query {{ 
          flow_run_by_pk ( id: "{flow_run_id}" ),
        {{ 
            id, 
            flow {{
              id,
              name,
              version
            }}
            state,
            start_time,
            end_time,
            state_message 
            task_runs {{
              id, 
              state, 
              state_message,
              start_time,
              end_time,
              task {{
                id,
                name,
                slug,
                type
              }}
            }}
          }}
        }}"""
    )
    return
2 Views