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

28 lines
972 B
Python

from channels.layers import get_channel_layer
class NotificationDispatcher:
channel_layer = None
channel_name = 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...")
self.channel_name = await self.channel_layer.new_channel()
print("Channel name:", self.channel_name)
while True:
# Blocking receive to get the message from the channel layer
message = await self.channel_layer.receive(self.channel_name)
if message:
# Process the received message
print("Received message:", message)
await self.dispatch(message)
async def dispatch(self, message):
print("Dispatching message:", message)