pyoaev.daemons.base_daemon ========================== .. py:module:: pyoaev.daemons.base_daemon Module Contents --------------- .. py:class:: BaseDaemon(configuration: pyoaev.configuration.Configuration, callback: callable = None, logger=None, api_client=None) Bases: :py:obj:`abc.ABC` A base class for implementing a kind of daemon that periodically polls a given callback. :param configuration: configuration to provide the daemon (allowing for looking up values within the callback for example) :type configuration: Configuration :param callback: a method or function to periodically call, defaults to None. :type callback: callable, optional :param logger: a logger object, to log events. if not supplied, a default logger will be spawned to provide this functionality. :type logger: Any :param api_client: an API client that will provide connectivity with other systems. :type api_client: Any .. py:attribute:: _configuration .. py:attribute:: _callback :value: None .. py:attribute:: api .. py:attribute:: logger .. py:method:: _setup() :abstractmethod: A run-once method that inheritors must implement. This serves to instantiate all useful objects and functionality for the implementor to run. .. py:method:: _start_loop() :abstractmethod: Starts the daemon's main execution loop. Implementors should implement the main execution logic in here. .. py:method:: _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...). .. py:method:: 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. .. py:method:: 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(). .. py:method:: get_id() Returns the daemon instance's ID contained in configuration. Configuration must define any of these keys: `id`, `collector_id`, `injector_id`. .. py:method:: __get_default_api_client(url, token) :classmethod: .. py:method:: __get_default_logger(log_level, name) :classmethod: