diff --git a/wlm_server/operation/views.py b/wlm_server/operation/views.py index dad70a1..c0712d0 100644 --- a/wlm_server/operation/views.py +++ b/wlm_server/operation/views.py @@ -1,7 +1,11 @@ +import json + from django.http import HttpResponse from django.contrib.auth.decorators import login_required from django.conf import settings from rest_framework.decorators import api_view +from channels.layers import get_channel_layer +from asgiref.sync import async_to_sync from operation.models import Operation from channel.models import Channel @@ -44,6 +48,11 @@ def handle_info(request, ch: int): if not is_wlm_running: task_handler = TaskHandler() task_handler.start() + notif = {'on': True} + channel_layer = get_channel_layer() + async_to_sync(channel_layer.group_send)( + f'channel_{ch}', {'type': 'notify', 'message': json.dumps(notif)} + ) if not is_channel_running: message = MessageInfo(ActionType.OPERATE, ch, {'on': True}) message_queue.push(message) @@ -57,4 +66,9 @@ def handle_info(request, ch: int): if not is_wlm_running: message = MessageInfo(ActionType.CLOSE, None, None) message_queue.push(message) + notif = {'on': False} + channel_layer = get_channel_layer() + async_to_sync(channel_layer.group_send)( + f'channel_{ch}', {'type': 'notify', 'message': json.dumps(notif)} + ) return HttpResponse(status=200)