<@ULVA73B9P> is there anyway to know at flow runti...
# marvin-in-the-wild
t
@Marvin is there anyway to know at flow runtime what the execution environment is, or what work pool the flow is running on? i want to be able to programatically distinguish whether a flow is being run locally or on a work pool
m
To programmatically distinguish whether a flow is being run locally or on a work pool, you can utilize Prefect's runtime context, which tracks information about the current flow or task run. It contains various internal objects used by Prefect and is accessible only during a run. While the runtime context does not directly provide the name of the work pool being used, you could potentially set environment variables or use metadata within your flow or deployment to track this information. For instance, you might define environment variables that indicate the execution environment or work pool when setting up your worker. By accessing the runtime context within your flow, you can make decisions based on these variables. However, the documentation does not provide a direct means of detecting the work pool from within the running flow. You can read more about the runtime context in Prefect's Runtime Context documentation and learn about work pools in Work Pools documentation. Unfortunately, there doesn't seem to be a straightforward method provided out of the box for distinguishing runtime environments, but with custom setup and environment variables, it can be achieved. Be mindful that this might involve some additional effort to set up and maintain this detection logic.
t
@Marvin what if i just set an environment variable in my dockerfile that i use to deploy flows on kubernetes, what do you think about that?
n
thats a good idea
or
env
in the
job_variables
section for that deployment
t
Cool, thank you! Sadly my idea for a solution didn't work so i'm back to the drawing board, this is the specific problem i have in case you have any ideas please? https://prefect-community.slack.com/archives/C03D12TE9HQ/p1714134219310299