Skip to main content

prefect.runner.runner

Runners are responsible for managing the execution of all deployments. When creating a deployment using either flow.serve or the serve utility, they also will poll for scheduled runs. Example:

Classes

ProcessMapEntry

Runner

Methods:

aadd_deployment

Registers the deployment with the Prefect API and will monitor for work once the runner is started. Async version. Args:
  • deployment: A deployment for the runner to register.

aadd_flow

Provides a flow to the runner to be run based on the provided configuration. Async version. Will create a deployment for the provided flow and register the deployment with the runner. Args:
  • flow: A flow for the runner to run.
  • name: The name to give the created deployment. Will default to the name of the runner.
  • interval: An interval on which to execute the current flow. Accepts either a number or a timedelta object. If a number is given, it will be interpreted as seconds.
  • cron: A cron schedule of when to execute runs of this flow.
  • rrule: An rrule schedule of when to execute runs of this flow.
  • paused: Whether or not to set the created deployment as paused.
  • schedule: A schedule object defining when to execute runs of this deployment. Used to provide additional scheduling options like timezone or parameters.
  • schedules: A list of schedule objects defining when to execute runs of this flow. Used to define multiple schedules or additional scheduling options like timezone.
  • concurrency_limit: The maximum number of concurrent runs of this flow to allow.
  • triggers: A list of triggers that should kick of a run of this flow.
  • parameters: A dictionary of default parameter values to pass to runs of this flow.
  • description: A description for the created deployment. Defaults to the flow’s description if not provided.
  • tags: A list of tags to associate with the created deployment for organizational purposes.
  • version: A version for the created deployment. Defaults to the flow’s version.
  • entrypoint_type: Type of entrypoint to use for the deployment. When using a module path entrypoint, ensure that the module will be importable in the execution environment.

add_deployment

Registers the deployment with the Prefect API and will monitor for work once the runner is started. Args:
  • deployment: A deployment for the runner to register.

add_flow

Provides a flow to the runner to be run based on the provided configuration. Will create a deployment for the provided flow and register the deployment with the runner. Args:
  • flow: A flow for the runner to run.
  • name: The name to give the created deployment. Will default to the name of the runner.
  • interval: An interval on which to execute the current flow. Accepts either a number or a timedelta object. If a number is given, it will be interpreted as seconds.
  • cron: A cron schedule of when to execute runs of this flow.
  • rrule: An rrule schedule of when to execute runs of this flow.
  • paused: Whether or not to set the created deployment as paused.
  • schedule: A schedule object defining when to execute runs of this deployment. Used to provide additional scheduling options like timezone or parameters.
  • schedules: A list of schedule objects defining when to execute runs of this flow. Used to define multiple schedules or additional scheduling options like timezone.
  • concurrency_limit: The maximum number of concurrent runs of this flow to allow.
  • triggers: A list of triggers that should kick of a run of this flow.
  • parameters: A dictionary of default parameter values to pass to runs of this flow.
  • description: A description for the created deployment. Defaults to the flow’s description if not provided.
  • tags: A list of tags to associate with the created deployment for organizational purposes.
  • version: A version for the created deployment. Defaults to the flow’s version.
  • entrypoint_type: Type of entrypoint to use for the deployment. When using a module path entrypoint, ensure that the module will be importable in the execution environment.

astop

Stops the runner’s polling cycle. Async version.

cancel_all

execute_bundle

Executes a bundle in a subprocess. Deprecated: Use execute_bundle() from prefect.bundles.execute instead.

execute_flow_run

Executes a single flow run with the given ID. Deprecated: Use FlowRunExecutorContext with EngineCommandStarter instead. Execution will wait to monitor for cancellation requests. Exits once the flow run process has exited. Returns:
  • The flow run process.

execute_in_background

Executes a function in the background.

handle_sigterm

Gracefully shuts down the runner when a SIGTERM is received.

has_slots_available

Determine if the flow run limit has been reached. Returns:
    • bool: True if the limit has not been reached, False otherwise.

last_polled

last_polled

reschedule_current_flow_runs

Reschedules all flow runs that are currently running. Deprecated: SIGTERM rescheduling is now handled inline by the CLI execute path. This should only be called when the runner is shutting down because it kill all child processes and short-circuit the crash detection logic.

start

Starts a runner. The runner will begin monitoring for and executing any scheduled work for all added flows. Args:
  • run_once: If True, the runner will through one query loop and then exit.
  • webserver: a boolean for whether to start a webserver for this runner. If provided, overrides the default on the runner
Examples: Initialize a Runner, add two flows, and serve them by starting the Runner:

stop

Stops the runner’s polling cycle.