command
This commit is contained in:
parent
644b3c0bc8
commit
cfa16d60d1
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
)
|
@ -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}")
|
||||
|
@ -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",
|
||||
)
|
Loading…
Reference in New Issue
Block a user