Make more of the WBE logging and '__repr__' message more useful

When running the examples, especially when running them in
TRACE/BLATHER/DEBUG logging level these updates make it more clear =
what is being processed, the messages being sent/acked/received and
what there contents are.

Change-Id: I94a497c9064df30197454ae480fe3d471ba1dc7d
This commit is contained in:
Joshua Harlow
2015-09-30 18:23:18 -07:00
parent ba4704cd18
commit 9658952b42
3 changed files with 23 additions and 14 deletions

View File

@@ -95,8 +95,8 @@ class WorkerTaskExecutor(executor.TaskExecutor):
request = self._requests_cache.get(task_uuid) request = self._requests_cache.get(task_uuid)
if request is not None: if request is not None:
response = pr.Response.from_dict(response) response = pr.Response.from_dict(response)
LOG.debug("Response with state '%s' received for '%s'", LOG.debug("Extracted response '%s' and matched it to"
response.state, request) " request '%s'", response, request)
if response.state == pr.RUNNING: if response.state == pr.RUNNING:
request.transition_and_log_error(pr.RUNNING, logger=LOG) request.transition_and_log_error(pr.RUNNING, logger=LOG)
elif response.state == pr.EVENT: elif response.state == pr.EVENT:

View File

@@ -104,9 +104,10 @@ LOG = logging.getLogger(__name__)
class Message(object): class Message(object):
"""Base class for all message types.""" """Base class for all message types."""
def __str__(self): def __repr__(self):
cls_name = reflection.get_class_name(self, fully_qualified=False) return ("<%s object at 0x%x with contents %s>"
return "<%s> %s" % (cls_name, self.to_dict()) % (reflection.get_class_name(self, fully_qualified=False),
id(self), self.to_dict()))
@abc.abstractmethod @abc.abstractmethod
def to_dict(self): def to_dict(self):
@@ -150,6 +151,14 @@ class Notify(Message):
def __init__(self, **data): def __init__(self, **data):
self._data = data self._data = data
@property
def topic(self):
return self._data.get('topic')
@property
def tasks(self):
return self._data.get('tasks')
def to_dict(self): def to_dict(self):
return self._data return self._data

View File

@@ -206,18 +206,18 @@ class ProxyWorkerFinder(WorkerFinder):
self._workers[topic] = worker self._workers[topic] = worker
return (worker, True) return (worker, True)
def _process_response(self, response, message): def _process_response(self, data, message):
"""Process notify message from remote side.""" """Process notify message sent from remote side."""
LOG.debug("Started processing notify message '%s'", LOG.debug("Started processing notify response message '%s'",
ku.DelayedPretty(message)) ku.DelayedPretty(message))
topic = response['topic'] response = pr.Notify(**data)
tasks = response['tasks'] LOG.debug("Extracted notify response '%s'", response)
with self._cond: with self._cond:
worker, new_or_updated = self._add(topic, tasks) worker, new_or_updated = self._add(response.topic,
response.tasks)
if new_or_updated: if new_or_updated:
LOG.debug("Received notification about worker '%s' (%s" LOG.debug("Updated worker '%s' (%s total workers are"
" total workers are currently known)", worker, " currently known)", worker, self._total_workers())
self._total_workers())
self._cond.notify_all() self._cond.notify_all()
if new_or_updated: if new_or_updated:
self.notifier.notify(self.WORKER_ARRIVED, {'worker': worker}) self.notifier.notify(self.WORKER_ARRIVED, {'worker': worker})