From 0046701dbb00d29bdc0241d996acede9e84d08d4 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Wed, 27 Nov 2024 16:01:54 +0300 Subject: [PATCH 1/3] send --- .deploy/deploy-dev.yaml | 33 --------------------------------- daemons/mailbox.py | 27 --------------------------- daemons/poll.py | 16 ---------------- daemons/worker.py | 24 +++++++++++++++--------- main.py | 8 +------- 5 files changed, 16 insertions(+), 92 deletions(-) delete mode 100644 daemons/mailbox.py delete mode 100644 daemons/poll.py diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index 1b47e52..2dc9fd8 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -2,23 +2,6 @@ version: "3.4" services: - - poll: - image: mathwave/sprint-repo:pizda-bot - command: poll - environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - STAGE: "development" - networks: - - queues-development - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - worker: image: mathwave/sprint-repo:pizda-bot command: worker @@ -37,22 +20,6 @@ services: parallelism: 1 order: start-first - mailbox: - image: mathwave/sprint-repo:pizda-bot - command: mailbox - environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - STAGE: "development" - networks: - - queues-development - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - pizda-bot-nginx: image: mathwave/sprint-repo:pizda-bot command: api diff --git a/daemons/mailbox.py b/daemons/mailbox.py deleted file mode 100644 index a6ebbc5..0000000 --- a/daemons/mailbox.py +++ /dev/null @@ -1,27 +0,0 @@ -import telebot -import os - -from daemons import base -from utils import queues - - -class Daemon(base.BaseDaemon, queues.TasksHandlerMixin): - def __init__(self): - super().__init__() - self.bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) - - @property - def queue_name(self): - return 'pizda_bot_mailbox' - - def execute(self): - self.poll() - - def process(self, payload): - body = { - 'chat_id': payload['chat_id'], - 'text': payload['message'], - } - if payload['action'] == 'reply': - body['reply_to_message_id'] = payload['reply_to'] - self.bot.send_message(**body) diff --git a/daemons/poll.py b/daemons/poll.py deleted file mode 100644 index ffc8f79..0000000 --- a/daemons/poll.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import json -import telebot - -from daemons import base -from telebot import types -from utils import queues - - -class Daemon(base.BaseDaemon): - def execute(self): - bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) - @bot.message_handler() - def do_action(message: types.Message): - queues.set_task('pizda_bot_worker', message.json, 1) - bot.polling() diff --git a/daemons/worker.py b/daemons/worker.py index 7e5675e..772c180 100644 --- a/daemons/worker.py +++ b/daemons/worker.py @@ -49,23 +49,29 @@ class Daemon(base.BaseDaemon, queues.TasksHandlerMixin): def reply(self, text: str, chat_id: int, message_id: int): queues.set_task( - 'pizda_bot_mailbox', + 'botalka_mailbox', { - 'action': 'reply', - 'message': text, - 'reply_to': message_id, - 'chat_id': chat_id + 'project': 'pizda-bot', + 'name': 'telegram-bot', + 'body': { + 'message': text, + 'reply_to_message_id': message_id, + 'chat_id': chat_id, + } }, 1, ) def send(self, text: str, chat_id: int): queues.set_task( - 'pizda_bot_mailbox', + 'botalka_mailbox', { - 'action': 'send', - 'message': text, - 'chat_id': chat_id + 'project': 'pizda-bot', + 'name': 'telegram-bot', + 'body': { + 'message': text, + 'chat_id': chat_id, + } }, 1, ) diff --git a/main.py b/main.py index 546a9f9..f31884a 100644 --- a/main.py +++ b/main.py @@ -2,15 +2,9 @@ import sys arg = sys.argv[-1] -if arg == 'poll': - from daemons import poll - daemon = poll.Daemon() -elif arg == 'worker': +if arg == 'worker': from daemons import worker daemon = worker.Daemon() -elif arg == 'mailbox': - from daemons import mailbox - daemon = mailbox.Daemon() else: from api import app app.run(host="0.0.0.0", port=1238) -- 2.45.2 From 510dc9b8f78f2552127a8f22c91cf63d87080cde Mon Sep 17 00:00:00 2001 From: emmatveev Date: Wed, 27 Nov 2024 16:20:04 +0300 Subject: [PATCH 2/3] fix --- daemons/worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daemons/worker.py b/daemons/worker.py index 772c180..6933645 100644 --- a/daemons/worker.py +++ b/daemons/worker.py @@ -54,7 +54,7 @@ class Daemon(base.BaseDaemon, queues.TasksHandlerMixin): 'project': 'pizda-bot', 'name': 'telegram-bot', 'body': { - 'message': text, + 'text': text, 'reply_to_message_id': message_id, 'chat_id': chat_id, } @@ -69,7 +69,7 @@ class Daemon(base.BaseDaemon, queues.TasksHandlerMixin): 'project': 'pizda-bot', 'name': 'telegram-bot', 'body': { - 'message': text, + 'text': text, 'chat_id': chat_id, } }, -- 2.45.2 From eadc1be6d39a9df5cc180b96ac74d5a5e6f79c45 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Wed, 27 Nov 2024 18:41:24 +0300 Subject: [PATCH 3/3] fix --- .deploy/deploy-dev.yaml | 2 -- .deploy/deploy-prod.yaml | 36 ------------------------------- .gitea/workflows/deploy-dev.yaml | 2 -- .gitea/workflows/deploy-prod.yaml | 2 -- 4 files changed, 42 deletions(-) diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index 2dc9fd8..01179c7 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -24,10 +24,8 @@ services: image: mathwave/sprint-repo:pizda-bot command: api environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV MONGO_HOST: "mongo.develop.sprinthub.ru" MONGO_PASSWORD: $MONGO_PASSWORD_DEV - PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN STAGE: "development" networks: - common-infra-nginx-development diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index f11e53a..e8432f1 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -2,23 +2,6 @@ version: "3.4" services: - - poll: - image: mathwave/sprint-repo:pizda-bot - command: poll - environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD - STAGE: "production" - networks: - - queues - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - worker: image: mathwave/sprint-repo:pizda-bot command: worker @@ -38,31 +21,12 @@ services: parallelism: 1 order: start-first - mailbox: - image: mathwave/sprint-repo:pizda-bot - command: mailbox - environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD - STAGE: "production" - networks: - - queues - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - pizda-bot-nginx: image: mathwave/sprint-repo:pizda-bot command: api environment: - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD MONGO_HOST: "mongo.sprinthub.ru" MONGO_PASSWORD: $MONGO_PASSWORD_PROD - PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN - STAGE: "production" networks: - common-infra-nginx deploy: diff --git a/.gitea/workflows/deploy-dev.yaml b/.gitea/workflows/deploy-dev.yaml index 2c6b44e..9515a0c 100644 --- a/.gitea/workflows/deploy-dev.yaml +++ b/.gitea/workflows/deploy-dev.yaml @@ -39,7 +39,5 @@ jobs: ref: dev - name: deploy env: - TELEGRAM_TOKEN_DEV: ${{ secrets.TELEGRAM_TOKEN_DEV }} MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }} - PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }} run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml pizda-bot-development diff --git a/.gitea/workflows/deploy-prod.yaml b/.gitea/workflows/deploy-prod.yaml index 2dbefe7..cd6e772 100644 --- a/.gitea/workflows/deploy-prod.yaml +++ b/.gitea/workflows/deploy-prod.yaml @@ -39,7 +39,5 @@ jobs: ref: prod - name: deploy env: - TELEGRAM_TOKEN_PROD: ${{ secrets.TELEGRAM_TOKEN_PROD }} MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }} - PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }} run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml pizda-bot -- 2.45.2