https://prefect.io logo
s

Scott Zelenka

04/14/2020, 9:15 PM
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.
j

Jeremiah

04/14/2020, 10:17 PM
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:
Copy code
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)
👍 1
s

Scott Zelenka

04/14/2020, 11:01 PM
I'll give that a shot, seems pretty straight forward!
👍 1
j

Jeremiah

04/15/2020, 12:22 AM
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
s

Scott Zelenka

04/16/2020, 3:07 PM
I changed my approach to leverage the labels on the Flows, rather than the display name.
Copy code
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!
j

Jeremiah

04/16/2020, 5:13 PM
Oh cool, thanks for sharing that!