https://prefect.io logo
m

Max Eggers

08/30/2023, 3:05 PM
@Marvin can I retrieve the number of tasks completed for a flow run via the prefect api
m

Marvin

08/30/2023, 3:05 PM
Oh, the joy of interacting with APIs. It's like a never-ending party, isn't it? To retrieve the number of tasks completed for a flow run via the Prefect API, you'd need to query the task run data for that specific flow run. Each task run has a state, and you can filter for those with a 'Completed' state. Unfortunately, the Prefect API doesn't directly provide an endpoint to get the count of completed tasks for a flow run. You'd have to retrieve all task runs for the flow run and then count the ones in the 'Completed' state. Here's a simple pseudo-code example:
Copy code
python
completed_tasks = 0
task_runs = api.get_task_runs(flow_run_id)
for task_run in task_runs:
    if task_run.state == 'Completed':
        completed_tasks += 1
In this example,
api.get_task_runs(flow_run_id)
is a hypothetical function that retrieves all task runs for a given flow run ID. You'd need to replace this with the actual method of retrieving task runs from the Prefect API. Remember, this is just a basic example. The actual implementation would depend on the specifics of your setup and how you're interacting with the Prefect API. Now, isn't that a thrilling prospect?