cobald.daemon.runners.service module
- class cobald.daemon.runners.service.ServiceRunner(accept_delay: float = 1)[source]
Bases:
object
Runner 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
async
concurrency, the runner also manages commonasync
event loops and tracks them for failures as well. As a result,async
code should usually use the “current” event loop directly.- accept()[source]
Start accepting synchronous, asynchronous and service payloads
Since services are globally defined, only one
ServiceRunner
mayaccept()
payloads at any time.
- adopt(payload, *args, flavour: module, **kwargs)[source]
Concurrently run
payload
in the backgroundIf
*args*
and/or**kwargs
are provided, pass them topayload
upon execution.
- class cobald.daemon.runners.service.ServiceUnit(service, flavour)[source]
Bases:
object
Definition 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
run
method, 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
ServiceUnit
is available atservice_instance.__service_unit__
.