Components — hermes 0.1 documentation

# Components

class `hermes.components.` `Component`(notification_pipe, error_strategy, error_queue, backoff_limit=16)

  Bases: `hermes.log.LoggerMixin`, `multiprocessing.process.Process`

  A class which can be used to create both listener and processor objects. Callers must implement `execute()` and can others if they so choose.

  The structure of calls:

        +-----------------+
        |      set_up     | <--------------+
        +-----------------+                |
                 +                         |
                 |                         |
                 |                         |   ERROR
                 V                         |
      +-----------------------+            |
      |      pre_execute      |            |
      |        execute        | +----------+
      |      post_execute     |
      +-----------------------+
                 +
                 |
                 |
                 V
      +-----------------------+
      |      tear_down        |
      +-----------------------+

  The Component class adds a foundation for you to build a fully-fledged processor or listener. You can add/modify as much as you like - sensitive methods have been identified.

  Parameters: | notification_pipe – The `Pipe`-like object to perform `select()` on. error_strategy – An object of type `AbstractErrorStrategy` to handle exceptions. error_queue – A `Queue`-like object to inform the `Client` through. backoff_limit – The maximum number of seconds to backoff a Component until it resets.

  `execute`(pre_exec_value)

    Must be overridden by callers. The return value will be passed to `post_execute()`

    Parameters: | pre_exec_value – The value returned by `pre_execute()`

  `ident`

    Returns: | `ident()` unless the Component has not been started and returns None.

  `is_alive`()

    Returns: | `is_alive()` unless the Component has not been started and returns False.

  `join`(**kwargs)

    Returns: | `join()` unless the Component has not been started and returns immediately.

  `post_execute`(exec_value)

    Can be safely overridden by callers.

    Parameters: | exec_value – The value returned by `execute()`

  `pre_execute`()

    Can be safely overridden by callers. The return value will be passed to `execute()`.

  `run`()

    The main Component loop.

    Callers should take great care when overriding.

  `set_up`()

    Called before execute methods and only once per iteration.

    Overridden methods should call super.

  `start`()

    Initialises the process, sets it to daemonic and starts.

  `tear_down`()

    Called after execute methods and only once per iteration.

    Can be used to tear down any resources.