Brandon Bertelsen
06/19/2023, 6:45 AMMarvin
06/19/2023, 6:46 AMpython
import pendulum
from httpx import AsyncClient
from prefect.settings import PREFECT_API_KEY, PREFECT_API_URL
async def get_last_successful_flow_run(flow_name: str):
headers = {
"Authorization": "Bearer " + PREFECT_API_KEY.value(),
"Content-Type": "application/json",
}
async with AsyncClient() as client:
response = await <http://client.post|client.post>(
f"{PREFECT_API_URL.value()}/flow-runs/filter",
headers=headers,
json={
"filter": {
"flow": {"name": [flow_name]},
"state": {"state": ["Success"]},
},
"sort": {"timestamp": "desc"},
"limit": 1,
},
)
response.raise_for_status()
flow_runs = response.json()
if flow_runs:
last_successful_flow_run = flow_runs[0]
timestamp = pendulum.parse(last_successful_flow_run["timestamp"])
return timestamp
else:
return None
if __name__ == "__main__":
import asyncio
flow_name = "your_flow_name_here"
last_success_timestamp = asyncio.run(get_last_successful_flow_run(flow_name))
if last_success_timestamp:
print(f"The last successful flow run for '{flow_name}' was at {last_success_timestamp}")
else:
print(f"No successful flow runs found for '{flow_name}'")
Replace your_flow_name_here
with the name of the flow you're interested in. This script will print the date and time of the last successful flow run for the specified flow name.
I hope this helps you in your quest for flow success details. Remember, time flies like an arrow; fruit flies like a banana.Brandon Bertelsen
06/19/2023, 6:48 AMBrandon Bertelsen
06/19/2023, 11:43 AMMarvin
06/19/2023, 11:44 AMread_flows
method is a more straightforward approach. Let's dive into an example using the Prefect Client to find the last successful flow run's date and time by flow name:
python
from prefect import Client
import pendulum
def get_last_successful_flow_run(flow_name: str):
client = Client()
flows = client.read_flows(where={"name": {"_eq": flow_name}})
if not flows:
return None
flow_id = flows[0].id
flow_runs = client.read_flow_runs(
where={
"flow_id": {"_eq": flow_id},
"state": {"_eq": "Success"},
},
order_by={"timestamp": "desc"},
limit=1,
)
if flow_runs:
last_successful_flow_run = flow_runs[0]
timestamp = pendulum.parse(last_successful_flow_run.timestamp)
return timestamp
else:
return None
if __name__ == "__main__":
flow_name = "your_flow_name_here"
last_success_timestamp = get_last_successful_flow_run(flow_name)
if last_success_timestamp:
print(f"The last successful flow run for '{flow_name}' was at {last_success_timestamp}")
else:
print(f"No successful flow runs found for '{flow_name}'")
Replace your_flow_name_here
with the name of the flow you're interested in. This script will print the date and time of the last successful flow run for the specified flow name.
This should provide a more direct path to the information you seek. It's always good to have options, even if some are more convoluted than others.Brandon Bertelsen
06/19/2023, 12:24 PMMarvin
06/19/2023, 12:25 PMprefect
framework provided upon installation. It comes with several enhancements and changes compared to Prefect 1.0. Flows written with Prefect 1.0 will require modifications to run with Prefect 2.0. You can find the Prefect 2.0 documentation at docs.prefect.io, while the Prefect 1.0 documentation is now hosted at docs-v1.prefect.io [^1^].
Some notable changes in Prefect 2.0 include:
- Support for unmapped values to Task.map
- Local file system blocks created from the UI now point to the right base_path
- The deployment build
command now supports an optional output flag to customize the name of the deployment.yaml file, to better support projects with multiple flows [^1^].
Please note that future breaking changes will be less frequent, and more notice will be provided [^1^].
I hope this information helps you navigate the brave new world of Prefect 2.0. Remember, with great power comes great responsibility... or something like that.
[^1^]: Prefect Release Notes