Compare commits

..

4 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
4 changed files with 53 additions and 12 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

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

View File

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

View File

@@ -1,4 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
import datetime
import os import os
import zoneinfo
import requests import requests
import time import time
@@ -15,24 +18,54 @@ class QueuesException(Exception):
class TasksHandlerMixin: 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): def poll(self):
while True: 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') task = response.get('task')
if not task: if not task:
time.sleep(0.2) time.sleep(0.2)
continue continue
start = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
try: try:
print(f'process task with id {task["id"]}, attempt {task["attempt"]}')
self.process(task['payload']) self.process(task['payload'])
success = True
except Exception as exc: except Exception as exc:
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}') print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}')
continue success = False
try: end = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']}) if success:
if resp.status_code != 202: try:
raise QueuesException resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
except: if resp.status_code != 202:
print(f'Failed to finish task id={task["id"]}') 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 @property
def queue_name(self): def queue_name(self):