Merge pull request 'master' (#57) from master into dev

Reviewed-on: https://gitea.chocomarsh.com/self/botalka/pulls/57
This commit is contained in:
emmatveev 2025-06-15 03:30:33 +03:00
commit 08bc931a5a

View File

@ -1,6 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
import datetime import datetime
import os import os
from threading import Thread import zoneinfo
import requests import requests
import time import time
@ -12,6 +13,9 @@ else:
QUEUES_URL = 'http://queues:1239' QUEUES_URL = 'http://queues:1239'
executor = ThreadPoolExecutor(max_workers=1)
class QueuesException(Exception): class QueuesException(Exception):
... ...
@ -35,8 +39,7 @@ class TasksHandlerMixin:
print(f'metric failed: {e}') print(f'metric failed: {e}')
def send_metric(self, start, success, end): def send_metric(self, start, success, end):
# Thread(target=self._send_metric, args=(start, success, end)).start() executor.submit(self._send_metric, start, success, end)
self._send_metric(start, success, end)
def poll(self): def poll(self):
while True: while True:
@ -50,14 +53,14 @@ class TasksHandlerMixin:
if not task: if not task:
time.sleep(0.2) time.sleep(0.2)
continue continue
start = datetime.datetime.now() start = datetime.datetime.now().astimezone(zoneinfo.ZoneInfo("Europe/Moscow"))
try: try:
self.process(task['payload']) self.process(task['payload'])
success = True 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}')
success = False success = False
end = datetime.datetime.now() end = datetime.datetime.now().astimezone(zoneinfo.ZoneInfo("Europe/Moscow"))
try: try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']}) resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
if resp.status_code != 202: if resp.status_code != 202: