Hey there, was wondering if there is a REST API method in Prefect 2 to retrieve a flow's tasks names by flow name? either from a flow's Deployment or Flow objects (not from flow run)?
n
Nate
08/04/2024, 11:14 PM
hey @Ron Levi - yes! this sounds like POST /task_runs/filter, providing a deployment or flow run filter to narrow down the query
Nate
08/04/2024, 11:15 PM
there’s a client method read_task_runs you can use for this, @Marvin can you show a sample use of the read_task_runs method?
m
Marvin
08/04/2024, 11:15 PM
You can use the
read_task_runs
method from the
Prefect
client to fetch details about task runs. Below is an example that demonstrates how to use this method:
Copy code
from prefect.client import OrionClient
async def get_task_runs():
async with OrionClient() as client:
task_runs = await client.read_task_runs()
for task_run in task_runs:
print(task_run)
# Make sure to run this in an async environment.
import asyncio
asyncio.run(get_task_runs())
This script sets up an async function
get_task_runs
that establishes a connection to the Prefect Orion API client and fetches task runs using the
read_task_runs
method. The details of each task run are then printed to the console.
For more detailed examples of Prefect tasks, check out this sample code:
Prefect Code Example
n
Nate
08/04/2024, 11:17 PM
if you swap OrionClient for get_client then that’s right but it’ll give all of them, you’ll want to pass a filter something like this
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.