Created
February 2, 2022 10:35
-
-
Save prasanthkothuri/b6d1d8910f5bf6e185f2e3b8cea6cff3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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