Igor
09/15/2024, 11:23 AMMarvin
09/15/2024, 11:23 AMIgor
09/15/2024, 11:23 AMMarvin
09/15/2024, 11:24 AMDeployment.build_from_flow
method or the flow.deploy
method. Here are examples for each:
### Using Deployment.build_from_flow
python
from prefect.deployments import Deployment
from prefect.storage import GitHub
from prefect.infrastructure import KubernetesJob
if __name__ == "__main__":
Deployment.build_from_flow(
flow=my_flow, # Your flow
name="my-deployment",
storage=GitHub.load("demo-repo"),
entrypoint="example.py:my_flow",
infrastructure=KubernetesJob.load("my-k8s-job"),
infra_overrides=dict(pull_policy="Never"),
parameters=dict(name="Marvin"),
)
### Using flow.deploy
python
from prefect import flow
from prefect.storage import GitHub
my_flow = flow(...) # Define your flow
if __name__ == "__main__":
my_flow.deploy(
name="my-deployment",
work_pool_name="my-k8s-job",
job_variables=dict(pull_policy="Never"),
parameters=dict(name="Marvin"),
)
Both methods allow you to specify various deployment parameters, such as storage, infrastructure, and parameters for the flow execution.
For more detailed information, you can check out the Prefect deployment documentation here.Igor
09/15/2024, 11:28 AMMarvin
09/15/2024, 11:29 AM.server
and .deploy
in Prefect 3.0.2!
### .deploy
The .deploy
method is used to create a deployment for your flow. This deployment can be scheduled or triggered to run according to certain parameters and infrastructure configurations.
### .server
I couldn't find references to a .server
method directly related to Prefect flow deployments in the latest Prefect 3.0.2 documentation.
It’s likely that .server
might refer to server-related functionalities provided by the Prefect server or Prefect Cloud, where you can register and manage flows, orchestrate tasks, monitor runs, and more.
For creating and managing deployments, you should primarily use the .deploy
method.
### Further Reading
For more detailed instructions and examples:
- How to create deployments: Prefect Deploy Documentation
- Prefect Concepts: Prefect Concepts Guide
If you have specific use cases or further questions, let me know!Igor
09/15/2024, 11:29 AMMarvin
09/15/2024, 11:29 AM.serve
and .deploy
in Prefect 3.0.2:
### .deploy
- Purpose: Create a deployment for your flow, allowing it to be scheduled or run on specific infrastructure.
- Usage: This is a one-time setup to register the flow with Prefect, enabling it to be scheduled and executed according to specified parameters.
- Example:
python
from prefect import flow
@flow
def my_flow():
print("Hello, Prefect!")
if __name__ == "__main__":
my_flow.deploy(name="my-deployment")
### .serve
- Purpose: Start a long-running process to ensure that your flows can execute remotely triggered or scheduled runs. Useful for running flows in local environments.
- Usage: This method is intended to keep the local process running, allowing it to handle scheduled or remotely triggered runs.
- Example:
python
import time
from prefect import flow, serve
@flow
def slow_flow(sleep: int = 60):
"Sleepy flow - sleeps the provided amount of time (in seconds)."
time.sleep(sleep)
if __name__ == "__main__":
slow_deploy = slow_flow.to_deployment(name="sleeper", interval=45)
serve(slow_deploy)
The serve()
function is a long-running process, so your script must be running actively, and you can stop it with CTRL+C
.
For more details, you can reference:
- Running flows in local processes: Run Flows in Local Processes
- Prefect CLI serve command: Prefect CLI Shell
This should give you a clear understanding of when to use each method. Let me know if you have more questions!