Compare commits
No commits in common. "9e72357600182c56553f1cd651e498c6fd5cf811" and "ef1d60e3683674e93aa13f9d41798879d85c5ef7" have entirely different histories.
9e72357600
...
ef1d60e368
@ -22,7 +22,6 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- configurator
|
- configurator
|
||||||
- queues-development
|
- queues-development
|
||||||
- monitoring
|
|
||||||
environment:
|
environment:
|
||||||
STAGE: "development"
|
STAGE: "development"
|
||||||
command: mailbox
|
command: mailbox
|
||||||
@ -39,5 +38,3 @@ networks:
|
|||||||
external: true
|
external: true
|
||||||
queues-development:
|
queues-development:
|
||||||
external: true
|
external: true
|
||||||
monitoring:
|
|
||||||
external: true
|
|
||||||
|
@ -22,7 +22,6 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- configurator
|
- configurator
|
||||||
- queues
|
- queues
|
||||||
- monitoring
|
|
||||||
environment:
|
environment:
|
||||||
STAGE: "production"
|
STAGE: "production"
|
||||||
command: mailbox
|
command: mailbox
|
||||||
@ -39,5 +38,3 @@ networks:
|
|||||||
external: true
|
external: true
|
||||||
queues:
|
queues:
|
||||||
external: true
|
external: true
|
||||||
monitoring:
|
|
||||||
external: true
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
import datetime
|
|
||||||
import os
|
import os
|
||||||
import zoneinfo
|
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -18,28 +15,6 @@ class QueuesException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class TasksHandlerMixin:
|
class TasksHandlerMixin:
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.executor = ThreadPoolExecutor(max_workers=4)
|
|
||||||
|
|
||||||
def _send_metric(self, start: datetime.datetime, end: datetime.datetime, success: bool):
|
|
||||||
try:
|
|
||||||
resp = requests.post('http://monitoring:1237/api/v1/metrics/task', 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,
|
|
||||||
})
|
|
||||||
if resp.status_code == 202:
|
|
||||||
print("Metric ok")
|
|
||||||
else:
|
|
||||||
print(f'metric not ok: {resp.status_code}')
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error sending metric: {e}")
|
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -52,22 +27,17 @@ class TasksHandlerMixin:
|
|||||||
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:
|
||||||
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}')
|
||||||
success = False
|
continue
|
||||||
end = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
|
try:
|
||||||
if success:
|
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
|
||||||
try:
|
if resp.status_code != 202:
|
||||||
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
|
raise QueuesException
|
||||||
if resp.status_code != 202:
|
except:
|
||||||
raise QueuesException
|
print(f'Failed to finish task id={task["id"]}')
|
||||||
except:
|
|
||||||
print(f'Failed to finish task id={task["id"]}')
|
|
||||||
self.executor.submit(self._send_metric, start, end, success)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def queue_name(self):
|
def queue_name(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user