Skip to content

Commit

Permalink
Call notify() when operation status is changed
Browse files Browse the repository at this point in the history
See also: #17
  • Loading branch information
BECATRUE committed Nov 28, 2024
1 parent 45d20f7 commit 7b2eaed
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wlm_server/operation/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,6 +31,11 @@ def handle_info(request, ch: int):
if not util.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 util.is_channel_running(ch):
message = MessageInfo(ActionType.OPERATE, ch, {'on': True})
message_queue.push(message)
Expand All @@ -39,4 +48,9 @@ def handle_info(request, ch: int):
if not util.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)

0 comments on commit 7b2eaed

Please sign in to comment.