Skip to content

Instantly share code, notes, and snippets.

@prasanthkothuri
Created February 2, 2022 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasanthkothuri/b6d1d8910f5bf6e185f2e3b8cea6cff3 to your computer and use it in GitHub Desktop.
Save prasanthkothuri/b6d1d8910f5bf6e185f2e3b8cea6cff3 to your computer and use it in GitHub Desktop.
import prefect
from datetime import datetime, timezone
client = prefect.Client()
flows = client.graphql(
{
'query': {
'flow': {
'id'
}
}
}
)
for flow in flows['data']['flow']:
flow_runs = client.graphql(
{
'query': {
'flow (where: {id: {_eq: "'+flow['id']+'"}})':{
'flow_runs':{
'id',
'name',
'start_time'
}
}
}
}
)
for flow_run in flow_runs['data']['flow'][0]['flow_runs']:
if flow_run['start_time']:
if (datetime.now() - datetime.strptime(flow_run['start_time'], '%Y-%m-%dT%H:%M:%S.%f+00:00')).days > 30:
print(flow_run['name'])
client.graphql(
{
'mutation': {
'delete_flow_run(input: {flow_run_id: "'+flow_run['id']+'"})':{
'success',
'error'
}
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment