Samuel Tober

    Samuel Tober

    1 year ago
    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
    Kevin Kho

    Kevin Kho

    1 year ago
    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
    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