Fernando Correia
02/28/2025, 5:44 PMMarvin
02/28/2025, 5:45 PMrequests
library, assuming you have the necessary API endpoint and authentication details:
python
import requests
# Replace with your Prefect server URL and API endpoint
prefect_server_url = "<http://your-prefect-server/api>"
flow_run_id = "your-flow-run-id" # Replace with your actual flow run ID
new_state = "Completed" # The state you want to set
# Endpoint to set the flow run state
url = f"{prefect_server_url}/flow_runs/{flow_run_id}/set_state"
# Replace with your actual API key if needed
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# Payload with the new state
payload = {
"state": new_state
}
response = <http://requests.post|requests.post>(url, headers=headers, json=payload)
if response.status_code == 200:
print("Flow run state updated successfully.")
else:
print(f"Failed to update flow run state: {response.text}")
Please ensure you replace placeholders like your-prefect-server
, your-flow-run-id
, and YOUR_API_KEY
with actual values. Also, verify the correct endpoint path with your Prefect server's API documentation or setup.
For more details, you might want to explore the Prefect API documentation or the source code directly. Here are some useful links:
- Prefect Flow Engine Source Code
- Prefect Settings and Profiles
If you need further assistance or details, I recommend checking the Prefect server's API documentation specific to your version.Fernando Correia
02/28/2025, 5:46 PMMarvin
02/28/2025, 5:46 PMpython
import requests
# Replace with your Prefect server URL and API endpoint
prefect_server_url = "<http://your-prefect-server/api>"
flow_run_id = "your-flow-run-id" # Replace with your actual flow run ID
# Endpoint to set the flow run state
url = f"{prefect_server_url}/flow_runs/{flow_run_id}/set_state"
# Replace with your actual API key if needed
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# Payload with the new state
payload = {
"state": {
"type": "Crashed",
"message": "The flow run has crashed due to an unexpected error.",
"data": {} # Additional data can be included if needed
}
}
response = <http://requests.post|requests.post>(url, headers=headers, json=payload)
if response.status_code == 200:
print("Flow run state updated to Crashed successfully.")
else:
print(f"Failed to update flow run state: {response.text}")
In this example, the state
field is a dictionary containing the type
set to "Crashed", a message
explaining the reason, and an optional data
field for additional context. Adjust this structure based on the actual API documentation or Prefect server version you are using.
If you have access to your Prefect server's API documentation, it will provide the exact requirements for the payload structure. For further customization, you might want to explore the Prefect Flow Engine Source Code for insights into state handling.