Hey team, is there a way to tell prefect “Retry al...
# ask-community
s
Hey team, is there a way to tell prefect “Retry all failed flows in the last day/hour/etc”?
n
Hi @Samuel Hinton - there's no direct call you could make to do this but you could use the client by querying for all failed flows after a certain time period, so something like this:
Copy code
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
s
That looks like a great solution. As someone unfamliar with graphql, are there examples or documentation on the prefect site as to how to reschedule the results of that query?
n
We don't have any docs on this particular use case, but you'd use a mutation like this:
Copy code
mutation setTaskRunStates($input: [set_task_run_state_input!]!) {
  set_task_run_states(input: { states: $input }) {
    states {
      id
    }
  }
}
to set task run states, and:
Copy code
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.