pyoaev.daemons.base_daemon

Module Contents

class pyoaev.daemons.base_daemon.BaseDaemon(configuration: pyoaev.configuration.Configuration, callback: callable = None, logger=None, api_client=None)

Bases: abc.ABC

A base class for implementing a kind of daemon that periodically polls a given callback.

Parameters:
  • configuration (Configuration) – configuration to provide the daemon (allowing for looking up values within the callback for example)

  • callback (callable, optional) – a method or function to periodically call, defaults to None.

  • logger (Any) – a logger object, to log events. if not supplied, a default logger will be spawned to provide this functionality.

  • api_client (Any) – an API client that will provide connectivity with other systems.

_configuration
_callback = None
api
logger
abstractmethod _setup()

A run-once method that inheritors must implement. This serves to instantiate all useful objects and functionality for the implementor to run.

abstractmethod _start_loop()

Starts the daemon’s main execution loop. Implementors should implement the main execution logic in here.

_try_callback()

Tries to call the configured callback. Note that if any error is thrown, it is immediately swallowed (but still logged) allowing the collector to keep running. This is useful for any transient issue (e.g. API endpoint down…).

start()

Start the daemon. This will run the implementor’s run-once setup method and follow-up with the main execution loop. Note that at this point, if there is no configured callback, the method will abort and kill the daemon.

set_callback(callback: callable)

Configures a callback to call in the main execution loop. If the callback was not provided in the daemon’s ctor, this should be set before calling start().

get_id()

Returns the daemon instance’s ID contained in configuration. Configuration must define any of these keys: id, collector_id, injector_id.

classmethod __get_default_api_client(url, token)
classmethod __get_default_logger(log_level, name)