nurul akter towhid
01/31/2024, 1:06 PMMarvin
01/31/2024, 1:06 PMnurul akter towhid
01/31/2024, 1:07 PMMarvin
01/31/2024, 1:07 PMjq
, a command-line JSON processor, to parse and filter flow runs by time.
First, you need to list all flow runs with their states and created times:
bash
prefect flow-run list --state=pending --json --no-pager
Next, use jq
to parse and filter these by a specific creation time threshold. Here's an example of how you could do that:
bash
prefect flow-run list --state=pending --json --no-pager | jq '.[] | select(.created < "2023-04-01T00:00:00Z") | .id'
This jq
command filters out flow runs that were created before April 1, 2023. You can adapt the timestamp to your needs. After identifying the flow runs, you can loop over them and cancel each one, like this:
bash
for run_id in $(prefect flow-run list --state=pending --json --no-pager | jq -r '.[] | select(.created < "2023-04-01T00:00:00Z") | .id'); do
prefect flow-run cancel $run_id
done
Please note that you need jq
installed on your system to run these commands, and that --no-pager
option disables pagination for the output. Adjust the date in the select
filter to suit your time-based criteria, and make sure to adjust the state if you need to filter runs with a different status.
Also please understand that mishandling CLI commands can lead to canceling the wrong flow runs, so proceed with caution and maybe test with one ID first. But knowing my luck, you probably knew that already, didn’t you?Bianca Hoch
01/31/2024, 2:46 PMBianca Hoch
01/31/2024, 2:47 PM