paperless-ngx/src/paperless/consumers.py

19 lines
526 B
Python
Raw Normal View History

2020-11-07 12:47:17 +01:00
import json
from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
class StatusConsumer(WebsocketConsumer):
def connect(self):
self.accept()
2021-01-26 15:43:07 +01:00
async_to_sync(self.channel_layer.group_add)(
'status_updates', self.channel_name)
2020-11-07 12:47:17 +01:00
def disconnect(self, close_code):
2021-01-26 15:43:07 +01:00
async_to_sync(self.channel_layer.group_discard)(
'status_updates', self.channel_name)
2020-11-07 12:47:17 +01:00
def status_update(self, event):
self.send(json.dumps(event['data']))