Jeremy Phelps
09/22/2021, 5:21 PMrequests
library? I need to cancel a bunch of flow runs but the Web interface is too cumbersome and the CLI tool doesn't support cancellation.
I notice that the browser has a token that only lasts a few minutes.Kevin Kho
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)
Jeremy Phelps
09/22/2021, 5:47 PMJeremy Phelps
09/22/2021, 5:49 PMKevin Kho
Jeremy Phelps
09/22/2021, 5:51 PMJeremy Phelps
09/22/2021, 5:52 PMKevin Kho
Jeremy Phelps
09/22/2021, 5:54 PMKevin Kho
client.graphql(query)
and cancel that way in a Python script?Jeremy Phelps
09/22/2021, 5:58 PMKevin Kho
client.graphql
is in the API hereKevin Kho
response = client.graphql(
f"""
query {{
flow_run_by_pk ( id: "{flow_run_id}" ),
{{
id,
flow {{
id,
name,
version
}}
state,
start_time,
end_time,
state_message
task_runs {{
id,
state,
state_message,
start_time,
end_time,
task {{
id,
name,
slug,
type
}}
}}
}}
}}"""
)
Jeremy Phelps
09/22/2021, 6:01 PMprefect.client.client.Client.cancel_flow_run
Python function. I'm not sure if that was there before, or if it's in the version of Prefect I'm using.Jeremy Phelps
09/22/2021, 6:03 PMprefect.client.client.Client.graphql
function. No wonder I didn't see it before.