Create a deployment for a flow by calling the serve
method.
serve
method.
flow.serve
will pause the schedule
for the deployment (if it has one).When running this in environments where restarts are expected use thepause_on_shutdown=False
flag to prevent this behavior:serve
method on flows exposes many options for the deployment.
Here’s how to use some of those options:
cron
: a keyword that allows you to set a cron string schedule for the deployment; see
schedules for more advanced scheduling optionstags
: a keyword that allows you to tag this deployment and its runs for bookkeeping and filtering purposesdescription
: a keyword that allows you to document what this deployment does; by default the
description is set from the docstring of the flow function (if documented)version
: a keyword that allows you to track changes to your deployment; uses a hash of the
file containing the flow by default; popular options include semver tags or git commit hashestriggers
: a keyword that allows you to define a set of conditions for when the deployment should run; see
triggers for more on Prefect Events concepts.serve
See this example that triggers downstream work on upstream events.CTRL+C
and your schedule automatically pauses.
serve()
is a long-running processTo execute remotely triggered or scheduled runs, your script with flow.serve
must be actively running.serve
utility along with the to_deployment
method of flows:
flow.to_deployment
interface exposes the exact same options as flow.serve
; this method
produces a deployment objectserve(...)
is called"sleeper"
deployment"sleeper"
deployment with different values for sleep
"sleeper"
deployment from the UI.deploy
method, the flow.from_source
method is used to define how to retrieve the flow that you want to serve.
from_source
flow.from_source
method on Flow
objects requires a source
and an entrypoint
.
source
source
of your deployment can be:
path/to/a/local/directory
https://github.com/org/repo.git
GitRepository
object that accepts
GitCredentials
for private repositoriesentrypoint
entrypoint
is the path to the file where the flow is located within that source
, in the form
hello
flow from the flows/hello_world.py
file in the PrefectHQ/examples
repository:
serve
method as a local flow: