Compare commits

...

7 Commits

Author SHA1 Message Date
70d0d31e20 Merge pull request 'metric' (#82) from metric into master
Reviewed-on: #82
2025-07-17 23:32:42 +03:00
Egor Matveev
5581786225 fix
All checks were successful
Deploy Prod / Build (pull_request) Successful in 25s
Deploy Prod / Push (pull_request) Successful in 11s
Deploy Prod / Deploy prod (pull_request) Successful in 10s
2025-07-17 23:27:52 +03:00
Egor Matveev
66b4348957 fix
All checks were successful
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 11s
2025-06-15 17:24:52 +03:00
Egor Matveev
33901b0a82 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 17s
2025-06-15 17:13:54 +03:00
Egor Matveev
7b9d264ef9 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 8s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 12s
2025-06-15 17:08:15 +03:00
Egor Matveev
a707a8b93e fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 7s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 18s
2025-06-15 16:49:40 +03:00
Egor Matveev
df3354a536 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 7s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 17s
2025-06-15 16:45:51 +03:00
7 changed files with 13 additions and 50 deletions

View File

@@ -22,7 +22,6 @@ services:
networks:
- configurator
- queues-development
- monitoring
environment:
STAGE: "development"
command: mailbox
@@ -39,5 +38,3 @@ networks:
external: true
queues-development:
external: true
monitoring:
external: true

View File

@@ -22,7 +22,6 @@ services:
networks:
- configurator
- queues
- monitoring
environment:
STAGE: "production"
command: mailbox
@@ -39,5 +38,3 @@ networks:
external: true
queues:
external: true
monitoring:
external: true

View File

@@ -5,6 +5,4 @@ COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
ENV PYTHONUNBUFFERED 1
RUN mkdir /usr/src/metrics
RUN chmod 777 run.sh
ENTRYPOINT ["./run.sh"]
ENTRYPOINT ["python", "main.py"]

View File

@@ -1,22 +0,0 @@
import os
from requests import post
import json
from daemons import base
class Daemon(base.Daemon):
def execute(self):
while True:
for file in os.listdir('/usr/src/metrics'):
data = open(f'/usr/src/metrics/{file}', 'r').read()
payload = json.loads(data)
resp = post('http://monitoring:1237/api/v1/metrics/task', json=payload)
if resp.status_code == 202:
print("Metric ok")
else:
print(f'metric not ok: {resp.status_code}')
os.remove(f'/usr/src/metrics/{file}')
break

View File

@@ -11,9 +11,6 @@ if __name__ == '__main__':
elif arg == 'mailbox':
print("mailbox is starting")
from daemons.mailbox import Daemon
elif arg == 'metrics':
print("metrics is starting")
from daemons.metrics import Daemon
else:
raise ValueError(f"Unknown param {arg}")

13
run.sh
View File

@@ -1,13 +0,0 @@
#!/bin/bash
# Start the first process
python3 main.py $1 &
# Start the second process
# python3 main.py metrics &
# Wait for any process to exit
wait -n
# Exit with status of process that exited first
exit $?

View File

@@ -1,6 +1,8 @@
from concurrent.futures import ThreadPoolExecutor
import datetime
import json
import os
import traceback
import uuid
import zoneinfo
import requests
@@ -19,9 +21,13 @@ 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):
with open(f'/usr/src/{uuid.uuid4()}.json', 'w') as fp:
fp.write(json.dumps({
def send():
requests.post(f'{QUEUES_URL}/api/v1/metric', json={
'service': 'botalka',
'queue': self.queue_name,
'success': success,
@@ -29,7 +35,9 @@ class TasksHandlerMixin:
"success": success,
"execution_time_ms": (end - start).microseconds // 1000,
"environment": stage,
}))
})
self.executor.submit(send)
def poll(self):
while True:
@@ -50,6 +58,7 @@ class TasksHandlerMixin:
success = True
except Exception as exc:
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}')
traceback.print_stack()
success = False
end = datetime.datetime.now(zoneinfo.ZoneInfo("Europe/Moscow"))
if success: