mirror of
https://github.com/Kozea/Radicale.git
synced 2025-09-15 20:36:55 +00:00
Code cleanup and refactoring
This commit is contained in:
parent
5253a464ab
commit
389a6b9906
5 changed files with 41 additions and 31 deletions
|
@ -1,8 +1,7 @@
|
|||
import pika
|
||||
import json
|
||||
|
||||
from radicale.hook import HookNotificationItem
|
||||
from radicale import hook
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Hook(hook.BaseHook):
|
||||
|
@ -24,24 +23,9 @@ class Hook(hook.BaseHook):
|
|||
def _make_declare_queue_synced(self, topic):
|
||||
self.channel.queue_declare(queue=topic)
|
||||
|
||||
def notify(self, content):
|
||||
if not isinstance(content, QueueItem):
|
||||
return
|
||||
self.channel.basic_publish(exchange='',
|
||||
routing_key=self.topic,
|
||||
body=content.to_json().encode(encoding=self.encoding))
|
||||
|
||||
|
||||
class QueueItemTypes(Enum):
|
||||
UPSERT = "upsert"
|
||||
DELETE = "delete"
|
||||
|
||||
|
||||
class QueueItem:
|
||||
|
||||
def __init__(self, queue_item_type, content):
|
||||
self.type = queue_item_type.value
|
||||
self.content = content
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
def notify(self, notification_item):
|
||||
if isinstance(notification_item, HookNotificationItem):
|
||||
self.channel.basic_publish(
|
||||
exchange='',
|
||||
routing_key=self.topic,
|
||||
body=notification_item.to_json().encode(encoding=self.encoding))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue