Compare commits

...

6 Commits

Author SHA1 Message Date
a767ab39d7 Update .deploy/deploy-dev.yaml
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 11s
Deploy Prod / Build (pull_request) Successful in 6s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 13s
2025-09-18 23:59:05 +03:00
c5ff370f75 Update .deploy/deploy-prod.yaml
Some checks failed
Deploy Dev / Build (pull_request) Successful in 24s
Deploy Dev / Push (pull_request) Successful in 14s
Deploy Dev / Deploy dev (pull_request) Failing after 4s
2025-09-18 23:55:57 +03:00
59770b1b0f Update .deploy/deploy-dev.yaml 2025-09-18 23:55:26 +03:00
Egor Matveev
26519dd977 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 25s
Deploy Dev / Push (pull_request) Successful in 14s
Deploy Dev / Deploy dev (pull_request) Successful in 19s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 8s
Deploy Prod / Deploy prod (pull_request) Successful in 12s
2025-06-15 17:28:45 +03:00
Egor Matveev
4b67bf10d3 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 7s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 9s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 8s
Deploy Prod / Deploy prod (pull_request) Successful in 11s
2024-12-31 18:21:39 +03:00
Egor Matveev
0ebb75de64 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 9s
Deploy Dev / Push (pull_request) Successful in 15s
Deploy Dev / Deploy dev (pull_request) Successful in 46s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 15s
2024-12-27 12:31:05 +03:00
6 changed files with 58 additions and 14 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -6,12 +6,13 @@ services:
image: mathwave/sprint-repo:pizda-bot
command: worker
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development"
networks:
- queues-development
- configurator
- mongo-development
deploy:
mode: replicated
restart_policy:
@@ -24,11 +25,12 @@ services:
image: mathwave/sprint-repo:pizda-bot
command: api
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_HOST: "mongo"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development"
networks:
- common-infra-nginx-development
- mongo-development
deploy:
mode: replicated
restart_policy:
@@ -44,3 +46,5 @@ networks:
external: true
configurator:
external: true
mongo-development:
external: true

View File

@@ -6,12 +6,13 @@ services:
image: mathwave/sprint-repo:pizda-bot
command: worker
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
STAGE: "production"
networks:
- queues
- configurator
- mongo
deploy:
mode: replicated
restart_policy:
@@ -24,10 +25,11 @@ services:
image: mathwave/sprint-repo:pizda-bot
command: api
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_HOST: "mongo"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
networks:
- common-infra-nginx
- mongo
deploy:
mode: replicated
restart_policy:
@@ -43,3 +45,5 @@ networks:
external: true
configurator:
external: true
mongo:
external: true

View File

@@ -4,6 +4,5 @@ WORKDIR /usr/src/app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
RUN make gen
ENV PYTHONUNBUFFERED 1
ENTRYPOINT ["python", "main.py"]

View File

@@ -35,6 +35,10 @@ def get_answers():
return client.get_config('answers')
def get_ignored_users():
return client.get_config('ignored_users')['users']
def get_replies():
return client.get_config('replies')
@@ -151,6 +155,6 @@ class Daemon(base.Daemon, queues.TasksHandlerMixin):
else:
return
ans = get_answers().get(convert_text)
if ans is not None and randrange(1, 101) <= info["probability"]:
if ans is not None and randrange(1, 101) <= info["probability"] and message.from_user.id not in get_ignored_users():
self.reply(ans, message.chat.id, message.message_id)
mongo.inc(message.from_user.username, message.chat.id)

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': 'botalka',
'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):