Hey everyone, is there a good way to access flow-run metadata within a flow context? For example, a task that grabs the current flow-run-id or even an upstream task's duration. Or will pulling metadata need to be done in a separate flow?
Here's what I would suggest -- or at least something along these lines:
Copy code
from prefect import Flow, task, context
@task
def access_context():
# you can initialize context with custom variables
# Note, this can be done outside of a task too
with context(a=1, b=2) as c:
print(c.a) # 1
# you can also access metadata of the overall flow-run
print(context.flow_run_id)
# or task-run metadata
print(context.task_run_id)
# The task shown above will only work within a Flow!
access_context.run() # does not have context filled and will fail
with Flow("Grab that context!") as flow:
access_context() # has a context filled and works successfully
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.