Dzmitry-S
07/11/2024, 4:50 PMMarvin
07/11/2024, 4:51 PMdeploy()
method:
python
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
print("Running my flow")
if __name__ == "__main__":
Deployment(name="my_deployment", flow=my_flow).apply()
2. Setup Work Pools in Prefect Cloud:
Configure work pools on the servers where the flow should run. This can be done in the Prefect Cloud UI under the "Work Pools" section.
3. Run Workers:
On the target server where you want to run the flow, start a Prefect worker from the specified work pool:
sh
prefect worker start --pool your_work_pool_name
4. Specify Docker Container:
If you need the flow to run in a specific Docker container, specify the image in your deployment configuration:
python
Deployment(name="my_deployment", flow=my_flow, work_pool_name="your_work_pool_name", image="your-docker-image").apply()
### Links for Reference:
- Deployment Configuration
- Work Pools
This setup will ensure your flow can be orchestrated by Prefect but executed on another server, potentially using a specified Docker container.Dzmitry-S
07/11/2024, 4:53 PMMarvin
07/11/2024, 4:53 PMpython
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
print("Running my flow")
if __name__ == "__main__":
Deployment(name="my_local_deployment", flow=my_flow).apply()
### 2. Start Workers on Target Servers
On the server where you want to run the flow, start a Prefect worker:
sh
prefect worker start --pool work-pool-name
This command ensures that the worker is listening for tasks assigned to it from the specified work pool.
### 3. Specify Docker Container (If Needed)
If the execution needs to be within a Docker container, modify the deployment to include the Docker image:
python
Deployment(
name="my_local_docker_deployment",
flow=my_flow,
work_pool_name="your_work_pool_name",
image="your-docker-image"
).apply()
### Example Code for Reference
Here is some example code to get you started on running tasks remotely, which can be configured similarly for deploying and running flows:
LINK:
https://raw.githubusercontent.com/zzstoatzz/prefect-code-examples/main/examples/tasks/submitting.py
EXAMPLE:
python
import time
from prefect import flow, task
@task
def sleep(t: int):
print(f"Going to sleep for {t} seconds...")
time.sleep(t)
print("...and I'm awake!")
@flow(log_prints=True)
def my_flow():
sleep(3)
future = sleep.submit(2)
future.wait()
sleep.map([5] * 10)
if __name__ == "__main__":
my_flow()
### Additional Resources
- Deployments Documentation
- Workers Documentation
By following these steps, you can configure Prefect in an on-premises environment to deploy and run flows on different servers.Kevin Grismore
07/11/2024, 4:55 PMKevin Grismore
07/11/2024, 4:55 PMDzmitry-S
07/11/2024, 5:00 PMKevin Grismore
07/11/2024, 5:02 PMDzmitry-S
07/11/2024, 5:05 PMKevin Grismore
07/11/2024, 5:06 PM