Hello everyone, I had a general question about Pre...
# prefect-community
m
Hello everyone, I had a general question about Prefect's FlowRun as shown here: https://docs.prefect.io/core/idioms/flow-to-flow.html and I wanted to make sure that I was understanding and that this made sense for our use case. We are considering the idea of having a "monolithic program" that has commonly used functions so we can just set parameter values on other programs where things differ. For example, we have a commonly used connect_to_db method that all our software shares. With a FlowRun would it be possible for us to register a flow that does the database connection and returns the information back to the dependent flow? As in Flow1 calls connect_to_db flow, returns connection information back to Flow1 and proceeds on with the rest of the tasks.
k
Hey @Matthew Blau, I think the main issue here is the inability to pass the connection between flows, which is currently not supported in a first-class way. Under the hood of the
StartFlowRun
task is an API call to your backend services to create a new flow run, which is encapsulated to its own Flow Run. Most users get around this by passing these types of tasks in a base image of a
run_config
to be used across flows with a shared set of tasks, but these shared tasks are still imported into singular flows. However, I’m sure there are other ways around this that others can share to meet your use case!
a
For the database connection scenario, have you looked at
ResourceManager
? https://docs.prefect.io/core/idioms/resource-manager.html For my team, we didn't know about it and used state handlers to setup the database connection(s) when the flow enters running state, then close the connection(s) when it enters finished state, so I know that works too, even if it isn't a prefect idiom.
m
Thanks @Amanda Wee and @Kyle Moon-Wright for the quick replies. I will look into this some more. The idea of using state handlers is an interesting one