Maja
08/04/2025, 10:56 AMMarvin
08/04/2025, 10:56 AMMarvin
08/04/2025, 10:57 AMMaja
08/04/2025, 11:42 AMMarvin
08/04/2025, 11:43 AMMarvin
08/04/2025, 11:43 AMpython
from prefect import flow
from prefect.deployments import deploy
@flow
def flow1():
print("This is flow 1")
@flow
def flow2():
print("This is flow 2")
# Deploy multiple flows
if __name__ == "__main__":
# Deploy first flow
flow1.from_source(
source="<https://github.com/your-repo/your-project>",
entrypoint="flows.py:flow1"
).deploy(
name="flow1-deployment",
work_pool_name="your-work-pool"
)
# Deploy second flow
flow2.from_source(
source="<https://github.com/your-repo/your-project>",
entrypoint="flows.py:flow2"
).deploy(
name="flow2-deployment",
work_pool_name="your-work-pool"
)
2. Using CLI
You can also deploy multiple flows using the CLI by running multiple deploy commands:
bash
prefect deploy ./path/to/flows.py:flow1 -n "flow1-deployment"
prefect deploy ./path/to/flows.py:flow2 -n "flow2-deployment"
Key Points to Remember:
- Each flow gets its own deployment name and configuration
- You can deploy multiple flows from the same source code/repository
- All flows can share the same work pool if desired
- When using Docker, multiple flows can be packaged in the same image
Benefits:
- Simplified management of related flows
- Reduced resource usage when flows share the same image
- Easier maintenance when flows are part of the same codebase
I must say, it's rather like having multiple books in the same bag - much more efficient than carrying a separate bag for each book, though perhaps not quite as organized as the library at Babel.
Would you like to know more about specific deployment configurations or best practices for managing multiple flows?Maja
08/04/2025, 11:45 AMMarvin
08/04/2025, 11:45 AMMarvin
08/04/2025, 11:46 AMpython
from prefect import flow
from prefect.deployments import deploy
from datetime import timedelta
@flow
def flow1():
print("This is flow 1")
@flow
def flow2():
print("This is flow 2")
if __name__ == "__main__":
# Deploy first flow with daily schedule
flow1.from_source(
source="<https://github.com/your-repo/your-project>",
entrypoint="flows.py:flow1"
).deploy(
name="flow1-deployment",
work_pool_name="your-work-pool",
interval=timedelta(days=1) # runs daily
)
# Deploy second flow with weekly schedule
flow2.from_source(
source="<https://github.com/your-repo/your-project>",
entrypoint="flows.py:flow2"
).deploy(
name="flow2-deployment",
work_pool_name="your-work-pool",
interval=timedelta(weeks=1) # runs weekly
)
In the Prefect Cloud UI, you'll see:
- Two separate deployments listed
- Each deployment with its own schedule
- Individual run histories
- Separate monitoring and logs
- Independent configuration options
Rather like having multiple clocks in different time zones - each one ticking away to its own rhythm, but all visible from the same control room. Much more sensible than trying to force everything to march to the same beat, wouldn't you say?
Would you like to know more about specific scheduling options or how to manage these deployments in the UI?Maja
08/04/2025, 11:47 AMMarvin
08/04/2025, 11:47 AMMarvin
08/04/2025, 11:47 AMpython
from prefect import flow
@flow
def child_flow_1():
print("Child flow 1")
@flow
def child_flow_2():
print("Child flow 2")
@flow
def parent_flow():
child_flow_1()
child_flow_2()
# This will create one deployment for the parent flow
parent_flow.from_source(
source="<https://github.com/your-repo/your-project>",
entrypoint="flows.py:parent_flow"
).deploy(
name="parent-flow-deployment",
work_pool_name="your-work-pool"
)
2. Use Flow References:
python
from prefect import flow
from prefect.deployments import run_deployment
@flow
def flow_1():
# This flow can trigger flow_2's deployment
run_deployment("flow-2/production")
The parent-child pattern is particularly useful if you want to:
- Orchestrate multiple flows together
- Share context between flows
- Maintain a single schedule for related flows
- Handle error handling and retries at a higher level
I must say, it's rather like trying to fit multiple books into one cover - while you can't do that literally, you can certainly write chapters that reference each other. Would you like to know more about parent-child flow patterns or flow orchestration strategies?