notification manager
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
@@ -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}")
|
||||
|
Reference in New Issue
Block a user