mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-01 18:18:31 +00:00
Code Cleanup and Optimisation
This commit is contained in:
parent
3882cf2bc8
commit
ecff5fac82
2 changed files with 12 additions and 11 deletions
|
@ -9,24 +9,24 @@ class Hook(hook.BaseHook):
|
|||
def __init__(self, configuration):
|
||||
super().__init__(configuration)
|
||||
endpoint = configuration.get("hook", "rabbitmq_endpoint")
|
||||
self.topic = configuration.get("hook", "rabbitmq_topic")
|
||||
self.encoding = configuration.get("encoding", "stock")
|
||||
self._topic = configuration.get("hook", "rabbitmq_topic")
|
||||
self._encoding = configuration.get("encoding", "stock")
|
||||
|
||||
self._make_connection_synced(endpoint)
|
||||
self._make_declare_queue_synced(self.topic)
|
||||
self._make_declare_queue_synced(self._topic)
|
||||
|
||||
def _make_connection_synced(self, endpoint):
|
||||
parameters = pika.URLParameters(endpoint)
|
||||
self.connection = pika.BlockingConnection(parameters)
|
||||
self.channel = self.connection.channel()
|
||||
connection = pika.BlockingConnection(parameters)
|
||||
self._channel = connection.channel()
|
||||
|
||||
def _make_declare_queue_synced(self, topic):
|
||||
self.channel.queue_declare(queue=topic)
|
||||
self._channel.queue_declare(queue=topic)
|
||||
|
||||
def notify(self, notification_item):
|
||||
if isinstance(notification_item, HookNotificationItem):
|
||||
self.channel.basic_publish(
|
||||
self._channel.basic_publish(
|
||||
exchange='',
|
||||
routing_key=self.topic,
|
||||
body=notification_item.to_json().encode(encoding=self.encoding)
|
||||
routing_key=self._topic,
|
||||
body=notification_item.to_json().encode(encoding=self._encoding)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue