Compare commits

..

21 Commits

Author SHA1 Message Date
62e61d21bf Merge pull request 'master' (#32) from master into prod
Reviewed-on: #32
2024-11-27 18:46:21 +03:00
eadc1be6d3 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 10s
2024-11-27 18:41:24 +03:00
510dc9b8f7 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 9s
2024-11-27 16:20:04 +03:00
0046701dbb send
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
2024-11-27 16:01:54 +03:00
5fd8147ff3 Merge pull request 'master' (#28) from master into prod
Reviewed-on: #28
2024-11-27 02:41:44 +03:00
e7109cc254 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 12s
Deploy Prod / Build (pull_request) Successful in 4s
Deploy Prod / Push (pull_request) Successful in 8s
Deploy Prod / Deploy prod (pull_request) Successful in 12s
2024-11-27 02:36:13 +03:00
dc7c222f50 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 11s
2024-11-27 02:33:09 +03:00
2d051a1881 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 13s
2024-11-27 02:20:49 +03:00
e6e3762768 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 13s
2024-11-27 02:17:26 +03:00
adc2525fab Merge pull request 'master' (#23) from master into prod
Reviewed-on: #23
2024-11-24 23:50:29 +03:00
8a4a6ac217 fix
All checks were successful
Deploy Prod / Build (pull_request) Successful in 4s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 14s
2024-11-24 18:10:34 +03:00
3d379bc6d7 configurator
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 14s
2024-11-24 18:05:52 +03:00
443b943bee Merge branch 'master' of https://gitea.sprinthub.ru/self/pizda-bot
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 14s
2024-11-23 22:37:50 +03:00
1d543461e9 fix 2024-11-23 22:36:58 +03:00
5967bc75d9 Merge pull request 'master' (#19) from master into prod
Reviewed-on: #19
2024-11-22 01:38:09 +03:00
37ac151e68 Merge pull request 'fix' (#18) from queues into master
All checks were successful
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 13s
Reviewed-on: #18
2024-11-22 01:37:44 +03:00
53e929fe5a Merge pull request 'queues' (#16) from queues into master
Reviewed-on: #16
2024-11-17 14:13:26 +03:00
f55b5f4841 Merge pull request 'queues' (#15) from queues into prod
Reviewed-on: #15
2024-11-17 13:32:22 +03:00
7713d24b63 Merge pull request 'fix' (#8) from master into prod
Reviewed-on: #8
2024-10-12 22:55:52 +03:00
1c82ef3b2b Merge pull request 'master' (#7) from master into prod
Reviewed-on: #7
2024-10-11 06:51:52 +03:00
a76656716c Merge pull request 'master' (#4) from master into prod
Reviewed-on: #4
2024-10-11 06:17:24 +03:00
10 changed files with 37 additions and 154 deletions

View File

@@ -2,23 +2,6 @@ version: "3.4"
services: services:
poll:
image: mathwave/sprint-repo:pizda-bot
command: poll
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
STAGE: "development"
networks:
- queues
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
worker: worker:
image: mathwave/sprint-repo:pizda-bot image: mathwave/sprint-repo:pizda-bot
command: worker command: worker
@@ -26,25 +9,9 @@ services:
MONGO_HOST: "mongo.develop.sprinthub.ru" MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development" STAGE: "development"
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
networks: networks:
- queues - queues-development
deploy: - configurator
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
mailbox:
image: mathwave/sprint-repo:pizda-bot
command: mailbox
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
STAGE: "development"
networks:
- queues
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -57,13 +24,11 @@ services:
image: mathwave/sprint-repo:pizda-bot image: mathwave/sprint-repo:pizda-bot
command: api command: api
environment: environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
MONGO_HOST: "mongo.develop.sprinthub.ru" MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "development" STAGE: "development"
networks: networks:
- common-infra-nginx - common-infra-nginx-development
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -73,7 +38,9 @@ services:
order: start-first order: start-first
networks: networks:
common-infra-nginx: common-infra-nginx-development:
external: true external: true
queues: queues-development:
external: true
configurator:
external: true external: true

View File

@@ -2,23 +2,6 @@ version: "3.4"
services: 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: worker:
image: mathwave/sprint-repo:pizda-bot image: mathwave/sprint-repo:pizda-bot
command: worker command: worker
@@ -29,22 +12,7 @@ services:
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
networks: networks:
- queues - queues
deploy: - configurator
mode: replicated
restart_policy:
condition: any
update_config:
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: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -57,11 +25,8 @@ services:
image: mathwave/sprint-repo:pizda-bot image: mathwave/sprint-repo:pizda-bot
command: api command: api
environment: environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
MONGO_HOST: "mongo.sprinthub.ru" MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "production"
networks: networks:
- common-infra-nginx - common-infra-nginx
deploy: deploy:
@@ -77,3 +42,5 @@ networks:
external: true external: true
queues: queues:
external: true external: true
configurator:
external: true

View File

@@ -28,7 +28,7 @@ jobs:
run: docker push mathwave/sprint-repo:pizda-bot run: docker push mathwave/sprint-repo:pizda-bot
deploy-dev: deploy-dev:
name: Deploy dev name: Deploy dev
runs-on: [dev] runs-on: [prod]
needs: push needs: push
steps: steps:
- name: login - name: login
@@ -39,7 +39,5 @@ jobs:
ref: dev ref: dev
- name: deploy - name: deploy
env: env:
TELEGRAM_TOKEN_DEV: ${{ secrets.TELEGRAM_TOKEN_DEV }}
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_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
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml pizda-bot

View File

@@ -39,7 +39,5 @@ jobs:
ref: prod ref: prod
- name: deploy - name: deploy
env: env:
TELEGRAM_TOKEN_PROD: ${{ secrets.TELEGRAM_TOKEN_PROD }}
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_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 run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml pizda-bot

View File

@@ -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)

View File

@@ -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()

View File

@@ -49,23 +49,29 @@ class Daemon(base.BaseDaemon, queues.TasksHandlerMixin):
def reply(self, text: str, chat_id: int, message_id: int): def reply(self, text: str, chat_id: int, message_id: int):
queues.set_task( queues.set_task(
'pizda_bot_mailbox', 'botalka_mailbox',
{ {
'action': 'reply', 'project': 'pizda-bot',
'message': text, 'name': 'telegram-bot',
'reply_to': message_id, 'body': {
'chat_id': chat_id 'text': text,
'reply_to_message_id': message_id,
'chat_id': chat_id,
}
}, },
1, 1,
) )
def send(self, text: str, chat_id: int): def send(self, text: str, chat_id: int):
queues.set_task( queues.set_task(
'pizda_bot_mailbox', 'botalka_mailbox',
{ {
'action': 'send', 'project': 'pizda-bot',
'message': text, 'name': 'telegram-bot',
'chat_id': chat_id 'body': {
'text': text,
'chat_id': chat_id,
}
}, },
1, 1,
) )

View File

@@ -2,15 +2,9 @@ import sys
arg = sys.argv[-1] arg = sys.argv[-1]
if arg == 'poll': if arg == 'worker':
from daemons import poll
daemon = poll.Daemon()
elif arg == 'worker':
from daemons import worker from daemons import worker
daemon = worker.Daemon() daemon = worker.Daemon()
elif arg == 'mailbox':
from daemons import mailbox
daemon = mailbox.Daemon()
else: else:
from api import app from api import app
app.run(host="0.0.0.0", port=1238) app.run(host="0.0.0.0", port=1238)

View File

@@ -14,11 +14,8 @@ class PlatformClient:
self.stage = stage self.stage = stage
self.configs = configs self.configs = configs
self.experiments = experiments self.experiments = experiments
self.endpoint = 'https://platform.sprinthub.ru/' self.endpoint = 'http://configurator/'
self.configs_url = urllib.parse.urljoin(self.endpoint, 'configs/get') self.fetch_url = urllib.parse.urljoin(self.endpoint, '/api/v1/fetch')
self.experiments_url = urllib.parse.urljoin(self.endpoint, 'experiments/get')
self.staff_url = urllib.parse.urljoin(self.endpoint, 'is_staff')
self.fetch_url = urllib.parse.urljoin(self.endpoint, 'fetch')
self.config_storage = {} self.config_storage = {}
self.experiment_storage = {} self.experiment_storage = {}
self.staff_storage = {} self.staff_storage = {}
@@ -43,7 +40,6 @@ class PlatformClient:
try: try:
response = get( response = get(
url, url,
headers={'X-Security-Token': self.platform_security_token},
params=params params=params
) )
if response.status_code == 200: if response.status_code == 200:

View File

@@ -18,22 +18,22 @@ class QueuesException(Exception):
class TasksHandlerMixin: class TasksHandlerMixin:
def poll(self): def poll(self):
while True: while True:
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}) response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json()
if response.status_code == 404: task = response.get('task')
if not task:
time.sleep(0.2) time.sleep(0.2)
continue continue
data = response.json()
try: try:
self.process(data['payload']) self.process(task['payload'])
except Exception as exc: except Exception as exc:
print(f'Error processing message id={data["id"]}, payload={data["payload"]}, exc={exc}') print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}')
continue continue
try: try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': data['id']}) resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
if resp.status_code != 202: if resp.status_code != 202:
raise QueuesException raise QueuesException
except: except:
print(f'Failed to finish task id={data["id"]}') print(f'Failed to finish task id={task["id"]}')
@property @property
def queue_name(self): def queue_name(self):