dispatcher: honour the priority of groups

This commit is contained in:
Noam Meltzer 2016-04-25 10:18:26 +03:00
parent 8a087dce69
commit 4ac8f86156

View file

@ -96,6 +96,9 @@ class Dispatcher(object):
self.update_queue = update_queue self.update_queue = update_queue
self.handlers = {} self.handlers = {}
""":type: dict[int, list[Handler]"""
self.groups = []
""":type: list[int]"""
self.error_handlers = [] self.error_handlers = []
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
@ -170,8 +173,8 @@ class Dispatcher(object):
self.dispatchError(None, update) self.dispatchError(None, update)
else: else:
for group in self.handlers.values(): for group in self.groups:
for handler in group: for handler in self.handlers[group]:
try: try:
if handler.checkUpdate(update): if handler.checkUpdate(update):
handler.handleUpdate(update, self) handler.handleUpdate(update, self)
@ -220,6 +223,8 @@ class Dispatcher(object):
if group not in self.handlers: if group not in self.handlers:
self.handlers[group] = list() self.handlers[group] = list()
self.groups.append(group)
self.groups = sorted(self.groups)
self.handlers[group].append(handler) self.handlers[group].append(handler)