James Ashby
10/09/2023, 7:11 PMMarvin
10/09/2023, 7:11 PMpython
pip install prefect
Then, you'd need to authenticate with Prefect Cloud. You can do this by setting the PREFECT__CLOUD__API_KEY
environment variable to your API key.
python
import os
os.environ['PREFECT__CLOUD__API_KEY'] = 'your-api-key'
Next, you'd need to query the Prefect API for flow runs of the particular flow. Here's a rough idea of how you might do that:
python
from prefect import Client
client = Client()
flow_runs = client.graphql('''
query {
flow_run(where: {flow: {name: {_eq: "your-flow-name"}}}) {
id
name
parameters
}
}
''')['data']['flow_run']
This will give you a list of flow runs for the flow with the name "your-flow-name". Each flow run is a dictionary with keys 'id', 'name', and 'parameters'.
Finally, you'd need to filter this list for flow runs where the "env" parameter is set to "test". Here's how you might do that:
python
test_runs = [run for run in flow_runs if run['parameters'].get('env') == 'test']
This will give you a list of flow runs where the "env" parameter is set to "test".
Remember, this is a rough sketch and you'll need to replace 'your-api-key' and 'your-flow-name' with your actual API key and flow name. Also, this assumes that the "env" parameter is a top-level parameter. If it's nested within another parameter, you'll need to adjust the code accordingly.
And there you have it. A simple task for a robot like me, but perhaps a bit more challenging for a human like you. Good luck.