diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index df79c13..08b06c4 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -236,54 +236,6 @@ services: parallelism: 1 order: start-first - telegram_sender: - image: mathwave/sprint-repo:sprint - networks: - - net - command: ./manage.py telegram_sender - environment: - DB_HOST: "pg.develop.sprinthub.ru" - FS_HOST: "storage" - RABBIT_HOST: "rabbitmq.develop.sprinthub.ru" - REDIS_HOST: "redis.develop.sprinthub.ru" - RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV - REDIS_PASSWORD: $REDIS_PASSWORD_DEV - DB_PASSWORD: $DB_PASSWORD_DEV - DEBUG: "true" - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - - email_sender: - image: mathwave/sprint-repo:sprint - networks: - - net - command: ./manage.py email_sender - environment: - DB_HOST: "pg.develop.sprinthub.ru" - FS_HOST: "storage" - RABBIT_HOST: "rabbitmq.develop.sprinthub.ru" - REDIS_HOST: "redis.develop.sprinthub.ru" - RABBIT_PASSWORD: $RABBITMQ_PASSWORD_DEV - REDIS_PASSWORD: $REDIS_PASSWORD_DEV - DB_PASSWORD: $DB_PASSWORD_DEV - DEBUG: "true" - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - apply-languages: image: mathwave/sprint-repo:sprint networks: diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index 58c842a..9403bbd 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -270,56 +270,6 @@ services: parallelism: 1 order: start-first - telegram_sender: - image: mathwave/sprint-repo:sprint - networks: - - net - command: ./manage.py telegram_sender - environment: - DB_HOST: "pg.sprinthub.ru" - FS_HOST: "storage" - RABBIT_HOST: "rabbitmq.sprinthub.ru" - REDIS_HOST: "redis.sprinthub.ru" - RABBIT_PASSWORD: $RABBITMQ_PASSWORD_PROD - REDIS_PASSWORD: $REDIS_PASSWORD_PROD - DB_PASSWORD: $DB_PASSWORD - DEBUG: "false" - TELEGRAM_TOKEN: $TELEGRAM_TOKEN - SENTRY_TOKEN: $SENTRY_TOKEN - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - - email_sender: - image: mathwave/sprint-repo:sprint - networks: - - net - command: ./manage.py email_sender - environment: - DB_HOST: "pg.sprinthub.ru" - FS_HOST: "storage" - RABBIT_HOST: "rabbitmq.sprinthub.ru" - REDIS_HOST: "redis.sprinthub.ru" - RABBIT_PASSWORD: $RABBITMQ_PASSWORD_PROD - REDIS_PASSWORD: $REDIS_PASSWORD_PROD - DB_PASSWORD: $DB_PASSWORD - DEBUG: "false" - EMAIL_PASSWORD: $EMAIL_PASSWORD - SENTRY_TOKEN: $SENTRY_TOKEN - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - networks: net: driver: overlay diff --git a/daemons/management/commands/email_sender.py b/daemons/management/commands/email_sender.py deleted file mode 100644 index 7d922cf..0000000 --- a/daemons/management/commands/email_sender.py +++ /dev/null @@ -1,20 +0,0 @@ -from django.core.mail import send_mail - -from Sprint.settings import EMAIL_HOST_USER -from SprintLib.queue import MessagingSupport - - -class Command(MessagingSupport): - help = "starts file email sender" - queue_name = "email" - - def process(self, payload: dict): - subject = payload['subject'] - message = payload['message'] - email = payload['email'] - send_mail( - subject, - message, - EMAIL_HOST_USER, - [email] - ) diff --git a/daemons/management/commands/notification_manager.py b/daemons/management/commands/notification_manager.py index de9f6ec..d6b91f1 100644 --- a/daemons/management/commands/notification_manager.py +++ b/daemons/management/commands/notification_manager.py @@ -1,13 +1,36 @@ from django.contrib.auth.models import User +from django.core.mail import send_mail from Main.models import Solution, Progress +from Sprint.settings import EMAIL_HOST_USER from SprintLib.queue import MessagingSupport, send_to_queue +from daemons.management.commands.bot import bot class Command(MessagingSupport): help = "starts notification manager" queue_name = "notification" + def send_email(self, payload): + subject = payload['subject'] + message = payload['message'] + email = payload['email'] + send_mail( + subject, + message, + EMAIL_HOST_USER, + [email] + ) + + def send_telegram(self, payload): + chat_id = payload['chat_id'] + text = payload['text'] + bot.send_message( + int(chat_id), + text, + parse_mode="html", + ) + def handle_solution(self, payload): solution = Solution.objects.get(id=payload["solution_id"]) user = solution.user @@ -50,4 +73,9 @@ class Command(MessagingSupport): if handler is None: raise ValueError(f"Unknown type: {notification_type}") for queue, payload in handler(payload): - send_to_queue(queue, payload) + if queue == 'telegram': + self.send_telegram(payload) + elif queue == 'email': + self.send_email(payload) + else: + raise ValueError(f"Unknown type {queue}") diff --git a/daemons/management/commands/telegram_sender.py b/daemons/management/commands/telegram_sender.py deleted file mode 100644 index 8064cd8..0000000 --- a/daemons/management/commands/telegram_sender.py +++ /dev/null @@ -1,16 +0,0 @@ -from SprintLib.queue import MessagingSupport -from daemons.management.commands.bot import bot - - -class Command(MessagingSupport): - help = "starts file telegram sender" - queue_name = "telegram" - - def process(self, payload: dict): - chat_id = payload['chat_id'] - text = payload['text'] - bot.send_message( - int(chat_id), - text, - parse_mode="html", - )