Thread
#prefect-community
    a

    Abhas P

    11 months ago
    Hi Team, Is there a way in prefect.core library/api to de-register or delete stale flows?
    Kevin Kho

    Kevin Kho

    11 months ago
    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

    Abhas P

    11 months ago
    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 ?
    from prefect.client.client import Client
    Client.graphql(query)
    Kevin Kho

    Kevin Kho

    11 months ago
    The query to get the flows in a project is this:
    query {
      flow (where: {project: {name: {_eq: "bristech"}}}) {
        name
        id
        project {
          name
        }
      }
    }
    The Client would be:
    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:
    mutation {
      delete_flow(input: {flow_id: "fb022314-8f78-484e-8e1d-e5cabedc10b6"}) {
        success
      }
    }
    And use the
    client.query()
    again for this.