Use GraphQL to Change State of Flow Run

You can use the Prefect Client to change the state of a Flow Run using Graphql with the following code:

from prefect.client import Client
client = Client()
query = """
mutation SetFlowRunStates($flowRunId: UUID!, $version: Int!, $state: JSON!) {
  set_flow_run_states(
    input: {
      states: [{ flow_run_id: $flowRunId, state: $state, version: $version }]
    }
  ) {
    states {
      id
      status
      message
    }
  }
}
"""
res = client.graphql(query, variables={
    "flowRunId": "e8a2a732-ac68-4ca9-81cc-1fa587021d30",
    "version": 4,
  	"state": {"type": "Failed", "message":"test"}
}
)
print(res)
1 Like