Common functionality

The existing DaemonMessage class would need to be altered or overridden to accept different operations at the Orchestrator, Worker, and Dispatcher levels, creating new namedtuple constants that are applicable for each. Initially, the Worker node would only be concerned with accepting calls to its factors_of method, and its allowed operations would reflect this:

WORKER_OPERATIONS = namedtuple(
    'WORKER_OPERATIONS', ['factors_of',]
)
( factors_of='factors_of', )

The corresponding change to the setter method for the operation property could use the appropriate namedtuple constant to control accepted values (for example, replacing _OPERATIONS with WORKER_OPERATIONS, in some fashion, for a Worker node's implementation):

    def _set_operation(self, value:str) -> None:
# - Other operations would need to be added 
        if not value in _OPERATIONS:
            raise ValueError(
                '%s.operation expects a string value (one of '
                '"%s"), but was passed "%s" (%s)' % 
                (
                    self.__class__.__name__, 
                    '", "'.join(_OPERATIONS._fields), 
                    value, type(value).__name__
                )
            )
        self._operation = value

Similarly, all three components would potentially need to know about all the possible origin values, in order to be able to assign message origins appropriately:

MESSAGE_ORIGINS = namedtuple(
    'MESSAGE_ORIGINS', ['orchestrator', 'worker', 'dispatcher']
)
( orchestrator='orchestrator', worker='worker', dispatcher='dispatcher', )

The main method of any of the individual daemons would remain essentially unchanged from how ArtisanGatewayDaemon implemented it.

In this approach, there are only a few distinct variations of a few class members for each of the daemon classes (Worker Node, Orchestrator, and Dispatcher), but they are worth noting because of their distinct nature. The bulk of the differences is in the _handle_message methods of each daemon class, and each would have to implement its own instance methods for the operations they map process requests to as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.96.247