1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Long poll adapters."""
12
from lp.services.messaging.queue import RabbitRoutingKey
15
def generate_event_key(*components):
16
"""Generate a suitable event name."""
17
if len(components) == 0:
19
"Event keys must contain at least one component.")
20
return "longpoll.event.%s" % ".".join(
21
str(component) for component in components)
25
"""Base-class for event adapters.
27
Sub-classes need to declare something along the lines of:
29
adapts(Interface, Interface)
30
implements(ILongPollEvent)
34
def __init__(self, source, event):
40
"""See `ILongPollEvent`."""
41
raise NotImplementedError(self.__class__.event_key)
44
"""See `ILongPollEvent`."""
45
payload = {"event_key": self.event_key, "event_data": data}
46
routing_key = RabbitRoutingKey(self.event_key)
47
routing_key.send(payload)