Samuel Hinton
03/19/2021, 6:02 PMnicholas
import datetime
from prefect import Client
client = Client()
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
query = f"""
query {
flow_run(where: {state: {_eq: "Failed", scheduled_start_time: { _gte: {yesterday} } }}) {
id
state
task_runs {
id
}
}
}
"""
result = client.graphql(query)
# iterate through results to set failed task runs to "Pending"
# and re-schedule the flow run
Samuel Hinton
03/19/2021, 6:53 PMnicholas
mutation setTaskRunStates($input: [set_task_run_state_input!]!) {
set_task_run_states(input: { states: $input }) {
states {
id
}
}
}
to set task run states, and:
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
}
}
}
to set flow run states; you'd want to make sure to set the task run states before setting the flow run state to Scheduled
. For more help using graphql, check out the graphql and hasura docs.