Jackie
09/20/2024, 9:16 PMSterling Baird
09/23/2024, 7:30 PMMarvin
09/23/2024, 7:30 PMpython
from prefect import flow
from prefect.context import get_run_context
@flow
def my_flow():
context = get_run_context()
flow_run_id = context.flow_run.id
print(f"Flow Run ID: {flow_run_id}")
my_flow()
For additional details, you can refer to the Prefect 2.x runtime context guide.
### Prefect 3.x
The Prefect 3.x documentation provides ways to access runtime information directly. Here's how you can achieve that:
python
from prefect import flow
from prefect.runtime import flow_run
@flow
def my_flow():
run_id = flow_run.id
print(f"Flow Run ID: {run_id}")
my_flow()
You can find more information in the Prefect 3.x runtime context documentation.
### Useful Documentation Links:
- Prefect 2.x Runtime Context
- Prefect 3.x Runtime Context
If you encounter any specific issues or need more advanced examples, feel free to let me know!Sterling Baird
09/23/2024, 7:32 PMMarvin
09/23/2024, 7:33 PMpython
from prefect import flow, task
from prefect.filesystems import S3
@flow(result_storage=S3(bucket_path="my-bucket"))
def my_flow():
my_task()
@task(persist_result=True, result_storage_key="my_task.json")
def my_task():
return "Task result"
my_flow()
In this case, the task's result will be persisted to 's3://my-bucket/my_task.json'.
For more details, check out the Prefect 2.x Results documentation.
### Prefect 3.x
In Prefect 3.x, result storage is similarly configured using blocks. The result storage path can be specified for the flow and tasks. You can review these paths in the Prefect Cloud UI under the specific flow runs details.
Here's a sample setup:
python
from prefect import flow, task
@flow(result_storage='s3-bucket/my-dev-block')
def my_flow():
my_task()
@task(persist_result=True, result_storage_key="my_task.json")
def my_task():
return "Task result"
my_flow()
By defining result_storage
in the flow and result_storage_key
in the task, you can control where the results are stored. The results in this case would be found under the specified S3 bucket.
For more sophisticated configurations and details, refer to the Prefect 3.x Results documentation.
### Accessing the Storage Path in the Prefect Cloud UI
To see the result storage path for a previous flow run in the Prefect Cloud UI:
1. Navigate to the specific flow run.
2. Look for result information or associated storage blocks/details in the flow run metadata.
### Useful Documentation Links:
- Prefect 2.x Results Storage
- Prefect 3.x Results Storage
Feel free to ask if you need more specific instructions or run into any issues!