prefect.server.services.base

Functions

run_multiple_services

run_multiple_services(loop_services: List[LoopService]) -> NoReturn
Only one signal handler can be active at a time, so this function takes a list of loop services and runs all of them with a global signal handler.

Classes

Service

Methods:

all_services

all_services(cls) -> Sequence[type[Self]]
Get list of all service classes

enabled

enabled(cls) -> bool
Whether the service is enabled

enabled_services

enabled_services(cls) -> list[type[Self]]
Get list of enabled service classes

environment_variable_name

environment_variable_name(cls) -> str

run_services

run_services(cls) -> NoReturn
Run enabled services until cancelled.

running

running(cls) -> AsyncGenerator[None, None]
A context manager that runs enabled services on entry and stops them on exit.

service_settings

service_settings(cls) -> ServicesBaseSetting
The Prefect setting that controls whether the service is enabled

start

start(self) -> NoReturn
Start running the service, which may run indefinitely

stop

stop(self) -> None
Stop the service

RunInAllServers

A marker class for services that should run in all server processes, both the web server and the standalone services process. Methods:

all_services

all_services(cls) -> Sequence[type[Self]]
Get list of all service classes

enabled

enabled(cls) -> bool
Whether the service is enabled

enabled_services

enabled_services(cls) -> list[type[Self]]
Get list of enabled service classes

environment_variable_name

environment_variable_name(cls) -> str

run_services

run_services(cls) -> NoReturn
Run enabled services until cancelled.

running

running(cls) -> AsyncGenerator[None, None]
A context manager that runs enabled services on entry and stops them on exit.

service_settings

service_settings(cls) -> ServicesBaseSetting
The Prefect setting that controls whether the service is enabled

start

start(self) -> NoReturn
Start running the service, which may run indefinitely

stop

stop(self) -> None
Stop the service

LoopService

Loop services are relatively lightweight maintenance routines that need to run periodically. This class makes it straightforward to design and integrate them. Users only need to define the run_once coroutine to describe the behavior of the service on each loop. Methods:

all_services

all_services(cls) -> Sequence[type[Self]]
Get list of all service classes

enabled

enabled(cls) -> bool
Whether the service is enabled

enabled_services

enabled_services(cls) -> list[type[Self]]
Get list of enabled service classes

environment_variable_name

environment_variable_name(cls) -> str

run_once

run_once(self) -> None
Represents one loop of the service. Subclasses must override this method. To actually run the service once, call LoopService().start(loops=1) instead of LoopService().run_once(), because this method will not invoke setup and teardown methods properly.

run_services

run_services(cls) -> NoReturn
Run enabled services until cancelled.

running

running(cls) -> AsyncGenerator[None, None]
A context manager that runs enabled services on entry and stops them on exit.

service_settings

service_settings(cls) -> ServicesBaseSetting
The Prefect setting that controls whether the service is enabled

start

start(self, loops: None = None) -> NoReturn
Run the service indefinitely.

start

start(self, loops: int) -> None
Run the service loops time. Args:
  • loops: the number of loops to run before exiting.

start

start(self, loops: int | None = None) -> None | NoReturn
Run the service loops time. Pass loops=None to run forever. Args:
  • loops: the number of loops to run before exiting.

start

start(self) -> NoReturn
Start running the service, which may run indefinitely

stop

stop(self, block: bool = True) -> None
Gracefully stops a running LoopService and optionally blocks until the service stops. Args:
  • block: if True, blocks until the service is finished running. Otherwise it requests a stop and returns but the service may still be running a final loop.

stop

stop(self) -> None
Stop the service