c3lf-system-3/core/mail/notifications.py
2024-06-23 04:31:27 +02:00

25 lines
823 B
Python

from channels.layers import get_channel_layer
class NotificationDispatcher:
channel_layer = None
def __init__(self):
self.channel_layer = get_channel_layer()
if not self.channel_layer:
raise Exception("Could not get channel layer")
async def run_forever(self):
# Infinite loop to continuously listen for messages
print("Listening for messages...")
while True:
# Blocking receive to get the message from the channel layer
message = await self.channel_layer.receive('general')
if message:
# Process the received message
print("Received message:", message)
await self.dispatch(message)
async def dispatch(self, message):
print("Dispatching message:", message)