Hello everyone! In a production environment that w...
# ask-community
w
Hello everyone! In a production environment that we have, we do not have access to the prefect UI and need to use the
prefect
CLI tool to do things like check which flows are running and see their logs. If a flow is running and I want to cancel it, how could I do this? There doesn't seem to be a command, and I'm assuming I need to do it with graphql. Is there an example of how to do this anyway? I appreciate it in advance.
k
Hey @William Grim, this is the query that the UI uses to cancel a flow run. Just supply the flow run id. You can also use the Prefect Client maybe. There is a method there to do it
cancel_flow_run
.
It’s pretty much the same. You can view the source here .
w
Oh cool! And I haven't attempted to run these queries directly. Is it something like an http post or anything?
k
Pretty much. You can do something like this:
Copy code
query = """query {flow{ name, id}}"""


url = '<https://api.prefect.io>'
r = <http://requests.post|requests.post>(url, json={'query': query}, headers={"authorization": "Bearer MY_TOKEN_HERE"})
print(r.status_code)
print(r.text)
But the Client is already authenticated for you. I think you’re thinking of just cURL directly? I think it might work.
w
Yeah, I was thinking of something like curl, but I can build on what you've written here.
I also was looking in my pycharm and digging down to how prefect does it based on your starting points.
Thank you!
k
Of course!
w
Just a quick follow-up that it doesn't seem like our graphql server even has auth tokens setup, which is something we'll have to rectify. But, at the very least, 3 lines of code was able to cancel a flow from a box that had the prefect libs installed:
Copy code
from prefect.client import Client
client = Client("<https://myurlhere>:myport")
client.cancel_flow_run("my_uuid_here")
Thanks again for the help! You made my life much better.
k
If you are using Prefect server, there is no auth. And of course!