Hi Team, Is there a way in prefect.core library/a...
# ask-community
a
Hi Team, Is there a way in prefect.core library/api to de-register or delete stale flows?
k
Hey @Abhas P, I don’t think we have a concept of stale flows. You might have to use the GraphQL API to handle this more complicated logic. You would need to query flows, maybe get the ones with empty flow runs, and then get those ids and pass them to the
delete_flow
mutation.
a
Let's say I know the names of flows I want to register (stored in list 1) and I want to delete all the registered flow which are not in the list : 1. How can I get the list of flow currently registered under a project ? 2. what would such a graphql query look like ?
Copy code
from prefect.client.client import Client
Client.graphql(query)
k
The query to get the flows in a project is this:
Copy code
query {
  flow (where: {project: {name: {_eq: "bristech"}}}) {
    name
    id
    project {
      name
    }
  }
}
The Client would be:
Copy code
from prefect.client.client import Client
client = Client()
client.graphql(query)
So I think this would be something like the query above, extract the flow names and the ids. Compare them with your list, and then you can loop over the ids you want to de-register and do:
Copy code
mutation {
  delete_flow(input: {flow_id: "fb022314-8f78-484e-8e1d-e5cabedc10b6"}) {
    success
  }
}
And use the
client.query()
again for this.