https://prefect.io logo
Title
f

Florian Guily

06/10/2022, 10:18 AM
Hello, i was wondering if there was a way to retrieve current flow run metadata such as id or time elapsed inside the code ?
2
a

Anna Geller

06/10/2022, 11:34 AM
Is this a question for Prefect 2.0 or 1.0 @Florian Guily?
f

Florian Guily

06/10/2022, 12:01 PM
1.0 🙂
a

Anna Geller

06/10/2022, 12:08 PM
the short answer is yes, but for things such as duration, you may need to do more work to get it https://docs.prefect.io/api/latest/utilities/context.html#context
e.g.
prefect.context.get("flow_run_id")
prefect.context.get("flow_id")
there is also scheduled_start_time depends on what you want to do, but context is a good place to get more info
there's also FlowRunView https://docs.prefect.io/api/latest/backend/flow_run.html#flowrunview but a bit more advanced and more "heavy" since this actually performs GraphQL queries under the hood
f

Florian Guily

06/10/2022, 12:53 PM
oh nice it is inside context. Thanks a lot !
👍 1