Merge branch 'abstract-messaging-repr'

This commit is contained in:
Nils Philippsen
2016-09-22 16:08:59 +02:00
3 changed files with 18 additions and 2 deletions

View File

@@ -11,3 +11,4 @@ Flask-Script
Flask-SQLAlchemy
Flask-Migrate
python-fedora
funcsigs # Python2 only

View File

@@ -25,6 +25,11 @@
"""Generic messaging functions."""
import re
try:
from inspect import signature
except ImportError:
from funcsigs import signature
from rida import logger
@@ -36,6 +41,17 @@ class BaseMessage(object):
"""
self.msg_id = msg_id
def __repr__(self):
init_sig = signature(self.__init__)
args_strs = (
"{}={!r}".format(name, getattr(self, name))
if param.default != param.empty
else repr(getattr(self, name))
for name, param in init_sig.parameters.items())
return "{}({})".format(type(self).__name__, ', '.join(args_strs))
@staticmethod
def from_fedmsg(topic, msg):
"""

View File

@@ -32,7 +32,6 @@ proper scheduling component builds in the supported build systems.
import inspect
import operator
import os
import pprint
import threading
import time
import six.moves.queue as queue
@@ -133,7 +132,7 @@ class MessageWorker(threading.Thread):
self.process_message(msg)
except Exception:
log.exception("Failed while handling %r" % msg.msg_id)
log.info(pprint.pformat(msg))
log.info(msg)
def process_message(self, msg):
log.debug('Received a message with an ID of "{0}" and of type "{1}"'