notification manager

This commit is contained in:
Egor Matveev
2022-03-20 16:11:06 +03:00
parent 9b3635723e
commit 0d7f2b9496
6 changed files with 65 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
import json
import pika
from django.contrib.auth.models import User
from django.core.management import BaseCommand
from pika.adapters.utils.connection_workflow import AMQPConnectorException
@@ -44,3 +45,11 @@ class MessagingSupport(BaseCommand):
channel.start_consuming()
except AMQPConnectorException:
print("connection to rabbit failed: reconnecting")
def notify(user: User, notification_type: str, text: str):
send_to_queue("notifications", {
'user_id': user,
'notification_type': notification_type,
'text': text,
})

View File

@@ -2,7 +2,7 @@ from os import listdir, mkdir
from os.path import join, exists
from subprocess import call, TimeoutExpired
from daemons.management.commands.bot import bot
from SprintLib.queue import notify
from Main.models import ExtraFile, SolutionFile
from Main.models.progress import Progress
from Sprint.settings import CONSTS
@@ -153,12 +153,10 @@ class BaseTester:
call(f"docker rm --force solution_{self.solution.id}", shell=True)
call(f"docker rm --force solution_{self.solution.id}_checker", shell=True)
self.solution.user.userinfo.refresh_from_db()
if self.solution.user.userinfo.notification_solution_result:
bot.send_message(
self.solution.user.userinfo.telegram_chat_id,
f"Задача: {self.solution.task.name}\n"
f"Результат: {self.solution.result}\n"
f"Очки решения: {Progress.by_solution(self.solution).score}\n"
f"Текущий рейтинг: {self.solution.user.userinfo.rating}",
parse_mode="html",
)
notify(
self.solution.user,
"solution_result",
f"Задача: {self.solution.task.name}\n"
f"Результат: {self.solution.result}\n"
f"Очки решения: {Progress.by_solution(self.solution).score}\n"
f"Текущий рейтинг: {self.solution.user.userinfo.rating}")