Compare commits

...

35 Commits

Author SHA1 Message Date
d670c9375c Merge pull request 'Update helpers/answer.py' (#33) from master into dev
Reviewed-on: #33
2025-09-14 10:13:51 +03:00
5e2c725bc2 Update helpers/answer.py
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 15s
Deploy Prod / Build (pull_request) Successful in 6s
Deploy Prod / Push (pull_request) Successful in 10s
Deploy Prod / Deploy prod (pull_request) Successful in 15s
2025-09-14 10:13:29 +03:00
11fbbf18f4 Merge pull request 'master' (#31) from master into dev
Reviewed-on: #31
2025-09-12 21:21:59 +03:00
595dfd0f6d Update .deploy/deploy-prod.yaml
All checks were successful
Deploy Dev / Build (pull_request) Successful in 52s
Deploy Dev / Push (pull_request) Successful in 28s
Deploy Dev / Deploy dev (pull_request) Successful in 15s
2025-09-12 21:20:29 +03:00
0990f684da Update .deploy/deploy-dev.yaml 2025-09-12 21:20:03 +03:00
Egor Matveev
5fa5789559 fix
All checks were successful
Deploy Prod / Build (pull_request) Successful in 4s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 14s
2025-06-15 23:30:50 +03:00
232042a523 Merge pull request 'fix' (#28) from master into dev
Reviewed-on: #28
2025-06-15 23:26:55 +03:00
Egor Matveev
7fcbb316e6 fix
Some checks failed
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 20s
Deploy Prod / Push (pull_request) Has been cancelled
Deploy Prod / Deploy prod (pull_request) Has been cancelled
Deploy Prod / Build (pull_request) Has been cancelled
2025-06-15 23:26:18 +03:00
eec041bb9d Merge pull request 'fix' (#27) from master into dev
Reviewed-on: #27
2025-06-15 15:02:56 +03:00
Egor Matveev
e9ecb7d94f fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 23s
2025-06-15 15:02:35 +03:00
e8b5092745 Merge pull request 'fix' (#26) from master into dev
Reviewed-on: #26
2025-06-15 15:01:42 +03:00
Egor Matveev
dbe5df157b fix
Some checks failed
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Failing after 7s
2025-06-15 15:01:22 +03:00
6c1288aaab Merge pull request 'master' (#25) from master into dev
Reviewed-on: #25
2025-06-15 14:58:04 +03:00
Egor Matveev
f4af02ec1d fix
Some checks failed
Deploy Dev / Push (pull_request) Successful in 25s
Deploy Dev / Build (pull_request) Successful in 48s
Deploy Dev / Deploy dev (pull_request) Failing after 6s
2025-06-15 14:56:49 +03:00
156e1407ed fix
All checks were successful
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 8s
Deploy Prod / Deploy prod (pull_request) Successful in 14s
2024-11-27 19:11:14 +03:00
3408364bc4 Merge pull request 'fix' (#22) from master into dev
Reviewed-on: #22
2024-11-27 16:38:24 +03:00
18aabe497b 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 14s
Deploy Prod / Build (pull_request) Successful in 4s
Deploy Prod / Push (pull_request) Successful in 8s
Deploy Prod / Deploy prod (pull_request) Successful in 20s
2024-11-27 16:37:59 +03:00
baa134ae26 Merge pull request 'fix' (#21) from master into dev
Reviewed-on: #21
2024-11-27 16:35:39 +03:00
144e5d4335 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 15s
2024-11-27 16:35:19 +03:00
fcb2713eaf Merge pull request 'master' (#20) from master into dev
Reviewed-on: #20
2024-11-27 16:31:02 +03:00
48ab0d1797 Merge branch 'master' of https://gitea.sprinthub.ru/self/ruz-bot
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 14s
2024-11-27 16:30:16 +03:00
ddfd5596d9 add 2024-11-27 16:29:37 +03:00
f8417edc94 Merge pull request 'queues' (#19) from queues into master
Reviewed-on: #19
2024-11-27 02:46:58 +03:00
d2247054e8 Merge pull request 'queues' (#17) from queues into dev
Reviewed-on: #17
2024-11-27 02:44:39 +03:00
ce550c31f4 Merge pull request 'fix' (#14) from queues into dev
Reviewed-on: #14
2024-11-25 00:01:04 +03:00
ba2f1bb768 Merge pull request 'queues' (#13) from queues into dev
Reviewed-on: #13
2024-11-24 23:55:59 +03:00
889a20609f Merge pull request 'fix' (#12) from queues into dev
Reviewed-on: #12
2024-11-23 22:32:00 +03:00
1c3d1566e5 Merge pull request 'fix' (#11) from queues into dev
Reviewed-on: #11
2024-11-23 22:27:17 +03:00
2b88479cec Merge pull request 'fix' (#10) from queues into dev
Reviewed-on: #10
2024-11-22 01:52:48 +03:00
7238d725dd Merge pull request 'fix' (#9) from queues into dev
Reviewed-on: #9
2024-11-22 01:48:32 +03:00
4a3fa3c2ab Merge pull request 'fix' (#8) from queues into dev
Reviewed-on: #8
2024-11-17 23:08:08 +03:00
45e1c0fe8a Merge pull request 'fix' (#7) from queues into dev
Reviewed-on: #7
2024-11-17 23:03:48 +03:00
989f7026ad Merge pull request 'fix' (#6) from queues into dev
Reviewed-on: #6
2024-11-17 22:58:40 +03:00
90378be7c5 Merge pull request 'queues' (#5) from queues into dev
Reviewed-on: #5
2024-11-17 22:56:27 +03:00
95e4f5e8da Merge pull request 'deploy' (#2) from master into dev
Reviewed-on: #2
2024-10-11 07:05:29 +03:00
9 changed files with 62 additions and 161 deletions

View File

@@ -3,29 +3,12 @@ version: "3.4"
services:
poll:
image: mathwave/sprint-repo:ruz-bot
environment:
STAGE: "development"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
networks:
- queues-development
command: poll
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
worker:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo.dev.chocomarsh.com"
STAGE: "development"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
networks:
- queues-development
- configurator
@@ -38,26 +21,10 @@ services:
parallelism: 1
order: start-first
mailbox:
image: mathwave/sprint-repo:ruz-bot
environment:
STAGE: "development"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
networks:
- queues-development
command: mailbox
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
fetch:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo.dev.chocomarsh.com"
STAGE: "development"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
@@ -75,7 +42,7 @@ services:
notify:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo.dev.chocomarsh.com"
STAGE: "development"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
@@ -93,14 +60,13 @@ services:
ruz-bot-nginx:
image: mathwave/sprint-repo:ruz-bot
networks:
- common-infra-nginx
- common-infra-nginx-development
- queues-development
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo.dev.chocomarsh.com"
STAGE: "development"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
networks:
- queues-development
command: api
deploy:
mode: replicated

View File

@@ -3,29 +3,12 @@ version: "3.4"
services:
poll:
image: mathwave/sprint-repo:ruz-bot
environment:
STAGE: "production"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
networks:
- queues
command: poll
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
worker:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo.chocomarsh.com"
STAGE: "production"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
networks:
- queues
- configurator
@@ -38,41 +21,21 @@ services:
parallelism: 1
order: start-first
mailbox:
image: mathwave/sprint-repo:ruz-bot
environment:
STAGE: "production"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
networks:
- queues
command: mailbox
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
fetch:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo.chocomarsh.com"
STAGE: "production"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
DEBUG: "false"
networks:
- queues
- configurator
command: fetch
deploy:
mode: replicated
restart_policy:
condition: any
placement:
constraints:
- node.role == worker
- node.labels.zone == ru
update_config:
parallelism: 1
order: start-first
@@ -80,22 +43,18 @@ services:
notify:
image: mathwave/sprint-repo:ruz-bot
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo.chocomarsh.com"
STAGE: "production"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
DEBUG: "false"
networks:
- queues
- configurator
command: notify
deploy:
mode: replicated
restart_policy:
condition: any
placement:
constraints:
- node.role == worker
- node.labels.zone == ru
update_config:
parallelism: 1
order: start-first
@@ -104,21 +63,17 @@ services:
image: mathwave/sprint-repo:ruz-bot
networks:
- common-infra-nginx
- configurator
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo.chocomarsh.com"
STAGE: "production"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
DEBUG: "false"
command: api
deploy:
mode: replicated
restart_policy:
condition: any
placement:
constraints:
- node.role == worker
- node.labels.zone == ru
update_config:
parallelism: 1
order: start-first

View File

@@ -41,5 +41,4 @@ jobs:
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 ruz-bot-development

View File

@@ -1,31 +0,0 @@
import telebot
import os
from daemons import base
from utils import queues
class Daemon(base.Daemon, queues.TasksHandlerMixin):
def __init__(self):
super().__init__()
self.bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
@property
def queue_name(self):
return 'ruz_bot_mailbox'
def execute(self):
self.poll()
def process(self, payload):
body = {
'chat_id': payload['chat_id'],
'text': payload['text'],
}
reply_markup = payload.get('reply_markup')
if reply_markup:
body['reply_markup'] = reply_markup
try:
self.bot.send_message(**body, parse_mode='Markdown')
except Exception as exc:
print('Error', str(exc))

View File

@@ -25,7 +25,7 @@ def process():
ans += f"🧑‍🏫 {(lesson['lecturer'] or 'Неизвестно')}\n"
if lesson.get('link', None):
ans += f"🔗 {lesson['link']}"
queues.set_task('ruz_bot_mailbox', {'text': f"Через {user['notify_minutes']} минут у тебя занятие!\n" + ans, 'chat_id': user["chat_id"]}, 1)
queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': f"Через {user['notify_minutes']} минут у тебя занятие!\n" + ans, 'chat_id': user["chat_id"], 'parse_mode': 'Markdown'}}, 1)
mongo.lessons_collection.update_one({"_id": lesson['_id']}, {"$set": {"notified": True}})
time_now = datetime.datetime.now()
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
@@ -40,7 +40,7 @@ def process():
else:
text = ruz.schedule_builder(lessons)
try:
queues.set_task('ruz_bot_mailbox', {'text': f"Уведомляю о занятиях! Твое расписание на {'сегодня' if user.get('daily_notify_today', True) else 'завтра'}:\n" + text, 'chat_id': user["chat_id"]}, 1)
queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': f"Уведомляю о занятиях! Твое расписание на {'сегодня' if user.get('daily_notify_today', True) else 'завтра'}:\n" + text, 'chat_id': user["chat_id"], 'parse_mode': 'Markdown'}}, 1)
except:
pass
mongo.users_collection.update_one(
@@ -72,7 +72,7 @@ def process():
else:
mess += "12 часов"
mess += "!\n\nТвоя первая пара:\n\n" + ans
queues.set_task('ruz_bot_mailbox', {'text': mess, 'chat_id': user["chat_id"]}, 1)
queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': mess, 'chat_id': user["chat_id"], 'parse_mode': 'Markdown'}}, 1)
start_of_day = datetime.datetime(year=time_now.year, month=time_now.month, day=time_now.day)
mongo.lessons_collection.update_many({"begin": {"$gte": start_of_day, "$lt": (start_of_day + datetime.timedelta(days=1))}, "user_email": user["email"]}, {"$set": {"notified_today": True}})
break

View File

@@ -1,15 +0,0 @@
import os
import telebot
from daemons import base
from telebot import types
from utils import queues
class Daemon(base.Daemon):
def execute(self):
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
@bot.message_handler()
def do_action(message: types.Message):
queues.set_task('ruz_bot_worker', message.json, 1)
bot.polling()

View File

@@ -55,13 +55,6 @@ class Answer:
def process(self):
user = User(self.user['chat_id'])
try:
bot_enabled_exp = platform.get_experiment('bot_enabled')
if not bot_enabled_exp['enabled'] or not eval(bot_enabled_exp['condition']):
return
except Exception as exc:
logging.info(exc)
return
getattr(
self,
"handle_state_" + self.user['state'],
@@ -74,10 +67,10 @@ class Answer:
def send_message(self, text, reply_markup=None, remove_keyboard=True, **kwargs):
if reply_markup is None and remove_keyboard:
reply_markup = ReplyKeyboardRemove()
body = {'text': text, 'chat_id': self.user['chat_id']}
body = {'text': text, 'chat_id': self.user['chat_id'], 'parse_mode': 'Markdown'}
if reply_markup:
body['reply_markup'] = reply_markup.to_json()
queues.set_task('ruz_bot_mailbox', body, 1)
queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': body}, 5)
def set_state(self, state: str):
self.user['state'] = state

View File

@@ -12,7 +12,8 @@ fields = [
'date_start',
'date_end',
'lecturer_profiles',
'stream_links'
'stream_links',
'type',
]

View File

@@ -1,4 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
import datetime
import os
import zoneinfo
import requests
import time
@@ -15,24 +18,54 @@ class QueuesException(Exception):
class TasksHandlerMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.executor = ThreadPoolExecutor(max_workers=1)
def _send_metric(self, start: datetime.datetime, end: datetime.datetime, success: bool):
def send():
requests.post(f'{QUEUES_URL}/api/v1/metric', json={
'service': 'ruz-bot',
'queue': self.queue_name,
'success': success,
'timestamp': start.strftime("%Y-%m-%dT%H:%M:%S") + "Z",
"success": success,
"execution_time_ms": (end - start).microseconds // 1000,
"environment": stage,
})
self.executor.submit(send)
def poll(self):
while True:
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json()
try:
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json()
except requests.JSONDecodeError:
print('Unable to decode json')
time.sleep(3)
continue
task = response.get('task')
if not task:
time.sleep(0.2)
continue
start = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
try:
print(f'process task with id {task["id"]}, attempt {task["attempt"]}')
self.process(task['payload'])
success = True
except Exception as exc:
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}')
continue
try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
if resp.status_code != 202:
raise QueuesException
except:
print(f'Failed to finish task id={task["id"]}')
success = False
end = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
if success:
try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
if resp.status_code != 202:
raise QueuesException
print(f'finish task with id {task["id"]}')
except:
print(f'Failed to finish task id={task["id"]}')
self._send_metric(start, end, success)
@property
def queue_name(self):
@@ -49,4 +82,4 @@ def set_task(queue_name: str, payload: dict, seconds_to_execute: int, delay: int
'delay': delay,
})
if resp.status_code != 202:
raise QueuesException
raise QueuesException