Merge pull request 'master' (#32) from master into prod
Reviewed-on: #32
This commit is contained in:
commit
62e61d21bf
@ -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,30 +20,12 @@ 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
|
||||
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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
@ -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()
|
@ -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': {
|
||||
'text': 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': {
|
||||
'text': text,
|
||||
'chat_id': chat_id,
|
||||
}
|
||||
},
|
||||
1,
|
||||
)
|
||||
|
8
main.py
8
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)
|
||||
|
Loading…
Reference in New Issue
Block a user