Hi Team, How can i get the current state or on whi...
# ask-community
n
Hi Team, How can i get the current state or on which task the flow currently is of a flow run in prefect. I have a flow run ID.
b
Hey Nimesh, you can use the REST api to query the states of task runs and flow runs. For flow runs, check out Read Flow Run state. For task runs, here's Read Task Run state.
n
Thanks Bianca for the response. I tried using the *GET*/api/flow_run_states/ API and got the below response. In the response i am not able to figure out where is the list of task and what are there current state. Can you please help me.
Copy code
[
  {
    "id": "3da490cc-ba0c-47f0-a239-83c207e89168",
    "type": "SCHEDULED",
    "name": "Scheduled",
    "timestamp": "2023-08-31T07:03:03.772419+00:00",
    "message": null,
    "data": null,
    "state_details": {
      "flow_run_id": "988e1d6b-0f15-4647-ba99-4f2db733f862",
      "task_run_id": null,
      "child_flow_run_id": null,
      "scheduled_time": "2023-08-31T07:03:03.759270+00:00",
      "cache_key": null,
      "cache_expiration": null,
      "untrackable_result": false,
      "pause_timeout": null,
      "pause_reschedule": false,
      "pause_key": null
    }
  },
  {
    "id": "f27b3e2c-0292-42a3-bfe8-d4242b3a9571",
    "type": "PENDING",
    "name": "Pending",
    "timestamp": "2023-08-31T07:03:07.313157+00:00",
    "message": null,
    "data": null,
    "state_details": {
      "flow_run_id": "988e1d6b-0f15-4647-ba99-4f2db733f862",
      "task_run_id": null,
      "child_flow_run_id": null,
      "scheduled_time": "2023-08-31T07:03:03.759270+00:00",
      "cache_key": null,
      "cache_expiration": null,
      "untrackable_result": false,
      "pause_timeout": null,
      "pause_reschedule": false,
      "pause_key": null
    }
  },
  {
    "id": "380f5d72-ba1f-43d1-98c6-6c97a1d72c78",
    "type": "RUNNING",
    "name": "Running",
    "timestamp": "2023-08-31T07:03:14.342251+00:00",
    "message": null,
    "data": null,
    "state_details": {
      "flow_run_id": "988e1d6b-0f15-4647-ba99-4f2db733f862",
      "task_run_id": null,
      "child_flow_run_id": null,
      "scheduled_time": null,
      "cache_key": null,
      "cache_expiration": null,
      "untrackable_result": false,
      "pause_timeout": null,
      "pause_reschedule": false,
      "pause_key": null
    }
  },
  {
    "id": "37be7bda-6d02-4ec6-b0d0-f4b0754764c9",
    "type": "COMPLETED",
    "name": "Completed",
    "timestamp": "2023-08-31T07:03:35.199534+00:00",
    "message": "All states completed.",
    "data": null,
    "state_details": {
      "flow_run_id": "988e1d6b-0f15-4647-ba99-4f2db733f862",
      "task_run_id": null,
      "child_flow_run_id": null,
      "scheduled_time": null,
      "cache_key": null,
      "cache_expiration": null,
      "untrackable_result": false,
      "pause_timeout": null,
      "pause_reschedule": false,
      "pause_key": null
    }
  }
]
Below is the list of task in the flow run. I want to get the the task and there current state.
b
Hello again, if you're looking to get the state of task runs, I'd recommend reading the task run state and filtering the results by specifying the
flow_run_id
That should return all records for task runs that belong to a given flow run
n
Is there any API that can give me flow_run_id (directly or indirectly). I have the deployment ID initially. Or is there any other way i can delete the flow using the deployment ID, if it is not in running state
I have the deployment ID and this highlighted one. My Goal is to delete a flow if it is not in a running state