Compare commits
No commits in common. "08bc931a5a9e8213570c7e4ff7f1e0d3fb3adeb2" and "fbc9c0e0d7b4d5a8053e339d5fbb46c587d0497c" have entirely different histories.
08bc931a5a
...
fbc9c0e0d7
@ -1,7 +1,6 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import zoneinfo
|
from threading import Thread
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -13,9 +12,6 @@ else:
|
|||||||
QUEUES_URL = 'http://queues:1239'
|
QUEUES_URL = 'http://queues:1239'
|
||||||
|
|
||||||
|
|
||||||
executor = ThreadPoolExecutor(max_workers=1)
|
|
||||||
|
|
||||||
|
|
||||||
class QueuesException(Exception):
|
class QueuesException(Exception):
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -39,7 +35,8 @@ 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):
|
||||||
executor.submit(self._send_metric, start, success, end)
|
# Thread(target=self._send_metric, args=(start, success, end)).start()
|
||||||
|
self._send_metric(start, success, end)
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
while True:
|
while True:
|
||||||
@ -53,14 +50,14 @@ class TasksHandlerMixin:
|
|||||||
if not task:
|
if not task:
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
continue
|
continue
|
||||||
start = datetime.datetime.now().astimezone(zoneinfo.ZoneInfo("Europe/Moscow"))
|
start = datetime.datetime.now()
|
||||||
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().astimezone(zoneinfo.ZoneInfo("Europe/Moscow"))
|
end = datetime.datetime.now()
|
||||||
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user