I’m wondering if it is possible to change which bl...
# ask-community
c
I’m wondering if it is possible to change which block to use within a task depending on the deployment version of a flow or is this a badly designed approach? For example, i have a flow that can either run 2 different types of infra (decided via deployments) but the db connection values will need to change depending on what infra it is using.
k
if you're `.load()`ing the block in your task, and there's two different deployments of that flow, you could have a param to the flow that selects the appropriate block name that differs per deployment
what's the different infra? maybe there's a more concise way to do it if the infra can be inferred from the execution environment
c
ahh okay gotcha. yeah, this is the approach i had in mind as well but was thinking there might be a better approach. For example, somehow through the actual
prefect.yaml
deployment file…most likely not. The 2 different infras is execution from within a google VM and a google cloud run.
The reason for the difference in db details for this example is that the cloud run job is connected to a vpc connector which needs to use the internal IP of the db (also on gcp, sql instance). Whereas, the VM (in a separate project unfortunately), is using the public IP (whitelisted as a connection). The potential gcp workaround would be to do some sort of shared vpc approach i think @Kevin Grismore
k
gotcha, if they're in the same project there's probably not an easy way to tell the difference at runtime
I've been looking into flow run context to see if there's any way to grab something like a deployment's tags or work pool to differentiate it but I haven't found anything yet
c
@Kevin Grismore it seems like
runtime.deployment.name
gives us deployment name actually: https://docs.prefect.io/2.13.7/guides/runtime-context/
k
ahaaaa
that seems useful
🙌 1
my advice here is that, while something like this will work, having something more explicit like a flow param still may be the best option. deployment names are easy to change, and you don't want to forget they have some kind of code dependency that breaks, so if you do use it, make sure you've got good error handling around it
c
thats a great point. I’ll definitely keep this in mind. The explicitly of the flow param is quite clear- the deployment name dependancy could easily be forgotten.