Scott Zelenka

    Scott Zelenka

    2 years ago
    Is it possible to use the CLI client to search for the Flows in a given Tenant/Project by the Flow Name? I'm trying to schedule a flow, where the user only has the display name of the Flow. I see
    client.create_flow_run
    but that want's the UUID. I'm looking for a display name to UUID map, similar to how the UI does it.
    Jeremiah

    Jeremiah

    2 years ago
    Flow names aren’t guaranteed unique but we could look at doing this on a “best effort” basis — in the meantime, you could use the client to issue the GQL to grab the ID, then pass that to the
    create_flow_run
    method. Here’sa quick example:
    import prefect
    from prefect.utilities.graphql import with_args
    
    query = {
        "query": {
            with_args("flow", {"where": {"name": {"_eq": "YOUR FLOW NAME"}}, "limit": 1}): {
                "id"
            }
        }
    }
    
    client = prefect.Client()
    result = client.graphql(query)
    client.create_flow_run(flow_id=result.data[0].id)
    Scott Zelenka

    Scott Zelenka

    2 years ago
    I'll give that a shot, seems pretty straight forward!
    Jeremiah

    Jeremiah

    2 years ago
    If the flow name matches multiple, potentially you could throw an
    order_by
    in to get the most recently created flow… lots of ways to ask for that ID. Once you find a pattern that works, let us know — always looking to streamline the CLI as a canonical access
    Scott Zelenka

    Scott Zelenka

    2 years ago
    I changed my approach to leverage the labels on the Flows, rather than the display name.
    query = {
        "query": {
            with_args("flow", {"where": "environment": {"_contains": {"labels": ["LABEL_NAME"]}}}, "limit": 100}): {
                "name", "version_group_id"
            }
        }
    }
    I need to validate that I can put multiple labels on a Flow, and have an Agent pick up the task when it's only listening for a subset of those labels, but it seems to get what I was after!
    Jeremiah

    Jeremiah

    2 years ago
    Oh cool, thanks for sharing that!