cobald.daemon.runners.service module
- class cobald.daemon.runners.service.ServiceRunner(accept_delay: float = 1)[source]
Bases:
objectRunner for coroutines, subroutines and services
The service runner prevents silent failures by tracking concurrent tasks and therefore provides safer concurrency. If any task fails with an exception or provides unexpected output values, this is registered as an error; the runner will gracefully shut down all tasks in this case.
To provide
asyncconcurrency, the runner also manages commonasyncevent loops and tracks them for failures as well. As a result,asynccode should usually use the “current” event loop directly.- accept()[source]
Start accepting synchronous, asynchronous and service payloads
Since services are globally defined, only one
ServiceRunnermayaccept()payloads at any time.
- adopt(payload, *args, flavour: ModuleType, **kwargs)[source]
Concurrently run
payloadin the backgroundIf
*args*and/or**kwargsare provided, pass them topayloadupon execution.
- execute(payload, *args, flavour: ModuleType, **kwargs)[source]
Synchronously run
payloadand provide its outputIf
*args*and/or**kwargsare provided, pass them topayloadupon execution.
- class cobald.daemon.runners.service.ServiceUnit(service, flavour)[source]
Bases:
objectDefinition for running a service
- Parameters:
service – the service to run
flavour – runner flavour to use for running the service
- property running
- start(runner: MetaRunner)[source]
- classmethod units() Set[ServiceUnit][source]
Container of all currently defined units
- cobald.daemon.runners.service.service(flavour)[source]
Mark a class as implementing a Service
Each Service class must have a
runmethod, which does not take any arguments. This method isadopt()ed after the daemon starts, unlessthe Service has been garbage collected, or
the ServiceUnit has been
cancel()ed.
For each service instance, its
ServiceUnitis available atservice_instance.__service_unit__.