Commit 785c647f authored by Julien Palard's avatar Julien Palard
Browse files

LOG: Some websocket info to help with debugging.

parent d03d0f19
......@@ -91,6 +91,7 @@ LOGGING = {
},
"loggers": {
"django": {"handlers": ["console", "mail_admins"], "level": "INFO"},
"website": {"handlers": ["console"], "level": "INFO"},
"django.server": {
"handlers": ["django.server"],
"level": "INFO",
......
import logging
from channels.generic.websocket import AsyncJsonWebsocketConsumer
logger = logging.getLogger(__name__)
class AnswerConsumer(AsyncJsonWebsocketConsumer):
async def connect(self):
self.user_id = self.scope["url_route"]["kwargs"]["user_id"]
self.exercise_id = self.scope["url_route"]["kwargs"]["exercise_id"]
logger.info(
"WS connect, user: %s, exercise: %s", self.user_id, self.exercise_id
)
self.groups = [
"answers.{}.{}".format(self.user_id, self.exercise_id),
"snippets.{}".format(self.user_id),
......@@ -15,11 +22,20 @@ class AnswerConsumer(AsyncJsonWebsocketConsumer):
await self.accept()
async def disconnect(self, close_code):
logger.info(
"WS disconnect, user: %s, exercise: %s", self.user_id, self.exercise_id
)
for group in self.groups:
await self.channel_layer.group_discard(group, self.channel_name)
async def correction(self, correction):
logger.info(
"WS push correction for user: %s, exercise: %s",
self.user_id,
self.exercise_id,
)
await self.send_json(correction)
async def snippet(self, snippet):
logger.info("WS push snippet for user: %s", self.user_id)
await self.send_json(snippet)
import logging
from asgiref.sync import async_to_sync
from django.db import models
from django.contrib.auth.models import User
......@@ -8,6 +9,9 @@ from channels.layers import get_channel_layer
from django_extensions.db.fields import AutoSlugField
logger = logging.getLogger(__name__)
class Exercise(models.Model):
title = models.CharField(max_length=255)
slug = AutoSlugField(populate_from=["title"], editable=True)
......@@ -69,7 +73,7 @@ def cb_new_answer(sender, instance, created, **kwargs):
def cb_new_snippet(sender, instance, created, **kwargs):
group = "snippets.{}".format(instance.user.id)
logger.info("New snippet notification for user %s", instance.user.id)
snippet = {"type": "snippet", "id": instance.id, "output": instance.output}
if instance.executed_at:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment