Paweł Biernat
07/24/2024, 1:25 PMMarvin
07/24/2024, 1:26 PMpersist_result=True
and appropriate result_storage_key
.
1. For retrieving the flow run result, use Prefect's API to access the stored result.
Here’s a practical example:
python
from prefect import flow, task
from prefect.filesystems import S3
@task(persist_result=True, result_storage_key="my_task.json")
def my_task():
return "Task result"
@flow(result_storage=S3(bucket_path="my-bucket"))
def my_flow():
return my_task()
my_flow() # The task's result will be persisted to '<s3://my-bucket/my_task.json>'
After executing the flow, you can retrieve the result from the persisted storage (e.g., S3 bucket in this case).
For further details, check out the documented example on persisted results here.
Another relevant resource can be found here.
If you need more tailored guidance for doing this programmatically, please let me know!Paweł Biernat
07/24/2024, 1:26 PMMarvin
07/24/2024, 1:26 PMpython
from prefect import get_client
from prefect.client.schemas import FlowRun
async def get_flow_run_result(flow_run_id: str):
async with get_client() as client:
flow_run = await client.read_flow_run(flow_run_id)
return flow_run.state.result()
# Example usage
import asyncio
flow_run_id = "your_flow_run_id_here"
flow_run_result = asyncio.run(get_flow_run_result(flow_run_id))
print(flow_run_result)
This code snippet does the following:
1. Establishes a connection with the Prefect client.
2. Reads the flow run using its ID.
3. Retrieves the result from the flow run's state.
This will give you the result of the flow run if it was successfully persisted.
For further details, you can check the official guide here.