mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:36:30 +00:00
write logs for inference and loader to file
This commit is contained in:
@@ -47,7 +47,7 @@ cdef class ApiClient:
|
||||
token = response.json()["token"]
|
||||
self.set_token(token)
|
||||
except HTTPError as e:
|
||||
constants.log(response.json())
|
||||
constants.logerror(response.json())
|
||||
if response.status_code == HTTPStatus.CONFLICT:
|
||||
res = response.json()
|
||||
raise Exception(res['Message'])
|
||||
@@ -95,7 +95,7 @@ cdef class ApiClient:
|
||||
r.raise_for_status()
|
||||
constants.log(f"Uploaded {filename} to {self.api_url}/{folder} successfully: {r.status_code}.")
|
||||
except Exception as e:
|
||||
constants.log(f"Upload fail: {e}")
|
||||
constants.logerror(f"Upload fail: {e}")
|
||||
|
||||
cdef list_files(self, str folder, str search_file):
|
||||
response = self.request('get', f'{self.api_url}/resources/list/{folder}', {
|
||||
@@ -173,7 +173,7 @@ cdef class ApiClient:
|
||||
resource = Security.decrypt_to(encrypted_bytes_small + local_bytes_big, key)
|
||||
return resource
|
||||
except Exception as ex:
|
||||
constants.log('Local file {folder}\\{big_part} doesnt match with api file, old version')
|
||||
constants.logerror('Local file {folder}\\{big_part} doesnt match with api file, old version')
|
||||
|
||||
remote_bytes_big = self.load_big_file_cdn(folder, big_part)
|
||||
return Security.decrypt_to(encrypted_bytes_small + remote_bytes_big, key)
|
||||
|
||||
@@ -30,6 +30,7 @@ venv\Scripts\pyinstaller --name=azaion-loader ^
|
||||
--collect-all boto3 ^
|
||||
--collect-all cryptography ^
|
||||
--collect-all yaml ^
|
||||
--collect-all loguru ^
|
||||
--hidden-import constants ^
|
||||
--hidden-import file_data ^
|
||||
--hidden-import remote_command ^
|
||||
|
||||
@@ -30,7 +30,7 @@ cdef class CDNManager:
|
||||
constants.log(f'uploaded {filename} ({len(file_bytes)} bytes) to the {bucket}')
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
constants.logerror(e)
|
||||
return False
|
||||
|
||||
cdef download(self, str folder, str filename):
|
||||
@@ -40,5 +40,5 @@ cdef class CDNManager:
|
||||
constants.log(f'downloaded {filename} from the {folder}')
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
constants.logerror(e)
|
||||
return False
|
||||
|
||||
@@ -14,4 +14,5 @@ cdef str MODELS_FOLDER
|
||||
cdef int SMALL_SIZE_KB
|
||||
|
||||
|
||||
cdef log(str log_message, bytes client_id=*)
|
||||
cdef log(str log_message)
|
||||
cdef logerror(str error)
|
||||
@@ -1,4 +1,6 @@
|
||||
import sys
|
||||
import time
|
||||
from loguru import logger
|
||||
|
||||
cdef str CONFIG_FILE = "config.yaml" # Port for the zmq
|
||||
|
||||
@@ -10,7 +12,34 @@ cdef str MODELS_FOLDER = "models"
|
||||
|
||||
cdef int SMALL_SIZE_KB = 3
|
||||
|
||||
cdef log(str log_message, bytes client_id=None):
|
||||
local_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
|
||||
client_str = '' if client_id is None else f' {client_id}'
|
||||
print(f'[{local_time}{client_str}]: {log_message}')
|
||||
cdef int ALIGNMENT_WIDTH = 32
|
||||
|
||||
logger.remove()
|
||||
log_format = "[{time:HH:mm:ss} {level}] {message}"
|
||||
logger.add(
|
||||
sink="Logs/log_loader_{time:YYYYMMDD}.txt",
|
||||
level="INFO",
|
||||
format=log_format,
|
||||
enqueue=True,
|
||||
rotation="1 day",
|
||||
retention="30 days",
|
||||
)
|
||||
logger.add(
|
||||
sys.stdout,
|
||||
level="DEBUG",
|
||||
format=log_format,
|
||||
filter=lambda record: record["level"].name in ("INFO", "DEBUG", "SUCCESS"),
|
||||
colorize=True
|
||||
)
|
||||
logger.add(
|
||||
sys.stderr,
|
||||
level="WARNING",
|
||||
format=log_format,
|
||||
colorize=True
|
||||
)
|
||||
|
||||
cdef log(str log_message):
|
||||
logger.info(log_message)
|
||||
|
||||
cdef logerror(str error):
|
||||
logger.error(error)
|
||||
@@ -1,6 +1,7 @@
|
||||
import threading
|
||||
from threading import Thread
|
||||
import traceback
|
||||
cimport constants
|
||||
from credentials cimport Credentials
|
||||
from remote_command cimport RemoteCommand, CommandType
|
||||
from remote_command_handler cimport RemoteCommandHandler
|
||||
@@ -29,7 +30,7 @@ cdef class CommandProcessor:
|
||||
self.shutdown_event.wait(timeout=1.0)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print('EXIT!')
|
||||
constants.log('EXIT!')
|
||||
|
||||
|
||||
cdef on_command(self, RemoteCommand command):
|
||||
@@ -66,7 +67,7 @@ cdef class CommandProcessor:
|
||||
else:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f"Error handling client: {e}")
|
||||
constants.logerror(f"Error handling client: {e}")
|
||||
err_command = RemoteCommand(CommandType.ERROR, None, str(e))
|
||||
self.remote_handler.send(command.client_id, err_command.serialize())
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ cdef class RemoteCommandHandler:
|
||||
for _ in range(4): # 4 worker threads
|
||||
worker = Thread(target=self._worker_loop, daemon=True)
|
||||
self._workers.append(worker)
|
||||
print(f'Listening to commands on port {zmq_port}...')
|
||||
constants.log(f'Listening to commands on port {zmq_port}...')
|
||||
|
||||
cdef start(self):
|
||||
self._proxy_thread.start()
|
||||
@@ -40,7 +40,7 @@ cdef class RemoteCommandHandler:
|
||||
zmq.proxy_steerable(self._router, self._dealer, control=self._control)
|
||||
except zmq.error.ZMQError as e:
|
||||
if self._shutdown_event.is_set():
|
||||
print("Shutdown, exit proxy loop.")
|
||||
constants.log("Shutdown, exit proxy loop.")
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -59,11 +59,11 @@ cdef class RemoteCommandHandler:
|
||||
client_id, message = worker_socket.recv_multipart()
|
||||
cmd = RemoteCommand.from_msgpack(<bytes> message)
|
||||
cmd.client_id = client_id
|
||||
constants.log(<str>f'{cmd}', client_id)
|
||||
constants.log(<str>f'{cmd}')
|
||||
self._on_command(cmd)
|
||||
except Exception as e:
|
||||
if not self._shutdown_event.is_set():
|
||||
constants.log(f"Worker error: {e}")
|
||||
constants.logerror(f"Worker error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
@@ -72,11 +72,6 @@ cdef class RemoteCommandHandler:
|
||||
cdef send(self, bytes client_id, bytes data):
|
||||
self._router.send_multipart([client_id, data])
|
||||
|
||||
# with self._context.socket(zmq.DEALER) as socket:
|
||||
# socket.connect("inproc://backend")
|
||||
# socket.send_multipart([client_id, data])
|
||||
# # constants.log(<str>f'Sent {len(data)} bytes.', client_id)
|
||||
|
||||
cdef stop(self):
|
||||
self._shutdown_event.set()
|
||||
try:
|
||||
|
||||
@@ -7,4 +7,5 @@ zmq
|
||||
requests
|
||||
pyyaml
|
||||
boto3
|
||||
loguru
|
||||
cryptography==44.0.2
|
||||
Reference in New Issue
Block a user