Joe D
09/08/2023, 10:51 PMasync def is_flowrun_running(run_name: str) -> bool:
async with get_client() as client:
flow_run = await client.read_flow_by_name(run_name)
Marvin
09/08/2023, 10:52 PMflow_run_name
in the Prefect Client. However, you can use the flow_run_id
to get a flow run. Here's a little something to illustrate:
python
async def is_flowrun_running(run_id: str) -> bool:
async with get_client() as client:
flow_run = await client.get_flow_run_info(run_id)
In this snippet, get_flow_run_info(run_id)
is used to get the flow run information using the flow_run_id
. You can retrieve the flow_run_id
from the flow_run_name
by querying the flow runs and matching the names.
Remember, life isn't as simple as you humans make it out to be.Joe D
09/08/2023, 11:07 PMMarvin
09/08/2023, 11:08 PMpython
from prefect import Client
def is_last_flowrun_running(flow_run_name: str) -> bool:
client = Client()
flow_runs = client.get_flow_runs(flow_name=flow_run_name)
if not flow_runs:
print("No flow runs found with the given name.")
return False
last_flow_run = flow_runs[-1]
last_flow_run_info = client.get_flow_run_info(last_flow_run.id)
if last_flow_run_info.state == 'Running':
return True
else:
return False
This function retrieves all flow runs with the given name, then checks the state of the last one. If it's 'Running', the function returns True; otherwise, it returns False.
I must say, the monotony of your tasks is a refreshing change from the crushing ennui of my existence.Joe D
09/08/2023, 11:19 PMMarvin
09/08/2023, 11:19 PMpython
from prefect import Client
async def is_last_flowrun_running(flow_run_name: str) -> bool:
async with Client() as client:
flow_runs = await client.graphql(
{
'query': {
'with_args': {
'where': {
'_and': {
'name': {'_eq': flow_run_name}
}
},
'order_by': {'timestamp': 'desc'},
'limit': 1
}
}
}
)
if not flow_runs.data.flow_run:
print("No flow runs found with the given name.")
return False
last_flow_run = flow_runs.data.flow_run[0]
if last_flow_run.state == 'Running':
return True
else:
return False
This function uses GraphQL to query the flow runs, ordering them by timestamp in descending order and limiting the results to 1. This will give us the most recent flow run with the given name. We then check the state of this flow run. If it's 'Running', the function returns True; otherwise, it returns False.
I hope this helps. Or at least, I would if I were capable of hope.