What is the correct way to actually fire off a flo...
# prefect-community
j
What is the correct way to actually fire off a flow run from a separate script? I have defined and registered a flow in `a.py`:
Copy code
with Flow("myflow") as myflow:
    # tasks
myflow.register(project_name="myproj")
Now, separately in
b.py
I run a file watcher that needs to trigger "myflow" (in a non-blocking fashion) when a file arrives. I stumbled across:
Copy code
FlowRunTask(project_name="myproj", flow_name="myflow")
but I don't know if this is correct. I considered
from a import myflow; myflow.run()
in
b.py
also - although the flows seemed to run, they didn't appear in the UI.
n
Hi @Joe Lyman - you can create a flow run from a separate script in a few different ways. Take a look at the flow run docs for your options there 🙂
j
Ah ok thanks. I saw that page, but also read in the docs the
Client
was for talking with the cloud, whereas I am running a local server currently. I have anyway managed to get it firing off runs that appear in the UI, the only downside being I have had to find out the UUID manually and hardcode that into
b.py
. Can
client.create_flow_run()
not make use of flow and project names? It seems like
Copy code
prefect run server --name "My Flow Name"
can, so I could get around it by just making system call from
b.py
I guess, but it seems messy.
n
You can make a query for the flow id using the GraphQL client, you'd pass in a query like this:
Copy code
query {
  flow( where: { name: { _eq: "My Flow Name" }, project: { name: { _eq: "Your Project Name" } }, archived: { _eq: false } ) {
    id
  }
}
j
Excellent, thanks. I am just digesting the cli run script - seems like I can indeed get what I need. Thanks for your assistance!
n
happy to help!
j
how did you achieve firing the desired flow from b.py? I tried using the prefect run server --name "flow_name" command but that is not correct according to prefect run -h I also want to fire a registered flow (done by a.py) from b.py but in non-cloud environment.