Dispatch: support multiple targets for a key

Brian S. Stephan 2013-05-03 16:01:45 -05:00
parent f09a41bce0
commit 88e470183b
1 changed files with 12 additions and 12 deletions

View File

@ -88,17 +88,17 @@ class Dispatch(Module):
message the message to send to the channel
tuple of strings: the destination channel, the string sent to it
list of all notified targets
key, dest = self._get_key_and_destination(key)
if key is not None and dest is not None:
notified = []
for key, dest in self._get_key_and_destination(key):
msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore'))
self.sendmsg(dest, msg)
return dest, msg
return notified
def _get_key_and_destination(self, key):
"""Retrieve the configured channel for the given key.
@ -107,11 +107,11 @@ class Dispatch(Module):
key the type of message. this will be converted uppercase
tuple of strings: the key (from the db), the destination channel
list of tuple of strings: (the key, the destination channel)
channel = None
targets = []
db = self.get_db()
cur = db.cursor(mdb.cursors.DictCursor)
@ -120,11 +120,11 @@ class Dispatch(Module):
WHERE key_ = %s
cur.execute(query, (key.upper(),))
result = cur.fetchone()
if result:
return result['key_'], result['dest']
return None, None
results = cur.fetchall()
for result in results:
targets.append((result['key_'], result['dest']))
return targets
except mdb.Error as e:
self.log.error("database error while getting destination")