diff --git a/wlm_server/operation/consumers.py b/wlm_server/operation/consumers.py new file mode 100644 index 0000000..5ee4c61 --- /dev/null +++ b/wlm_server/operation/consumers.py @@ -0,0 +1,16 @@ +from channels.generic.websocket import AsyncWebsocketConsumer + +class OperationConsumer(AsyncWebsocketConsumer): + """Consumer for notifying the operation change of a specific channel. + + Attributes: + ch: Target WLM channel. + group_name: Name of group it belongs to in the channel layer. + """ + + # pylint: disable=attribute-defined-outside-init + async def connect(self): + self.ch = self.scope['url_route']['kwargs']['ch'] + self.group_name = f'channel_{self.ch}' + await self.channel_layer.group_add(self.group_name, self.channel_name) + await self.accept()