add loader and versioning

This commit is contained in:
Alex Bezdieniezhnykh
2025-06-10 08:53:57 +03:00
parent 7750025631
commit dcd0fabc1f
31 changed files with 284 additions and 123 deletions
+16 -11
View File
@@ -2,10 +2,15 @@ import zmq
from remote_command cimport RemoteCommand, CommandType
from file_data cimport FileData, UploadFileData
cdef class LoadResult:
def __init__(self, str err, bytes data=None):
self.err = err
self.data = data
cdef class LoaderClient:
def __init__(self, str zmq_host, int zmq_port):
self._context = zmq.Context().instance()
self._socket = self._context.socket(zmq.DEALER)
self._loader_context = zmq.Context()
self._socket = self._loader_context.socket(zmq.DEALER)
self._socket.connect(f'tcp://{zmq_host}:{zmq_port}')
cdef RemoteCommand _send_receive_command(self, RemoteCommand command):
@@ -16,24 +21,24 @@ cdef class LoaderClient:
cdef FileData file_data = FileData(folder=directory, filename=filename)
cdef RemoteCommand response = self._send_receive_command(RemoteCommand(CommandType.LOAD_BIG_SMALL, data=file_data.serialize()))
if response.command_type == CommandType.DATA_BYTES:
return response.data
return LoadResult(None, response.data)
elif response.command_type == CommandType.ERROR:
raise Exception(f"Error from server: {response.message}")
return LoadResult(f"Error from server: {response.message}")
else:
raise Exception(f"Unexpected response command type: {response.command_type}")
return LoadResult(f"Unexpected response command type: {response.command_type}")
cdef upload_big_small_resource(self, bytes content, str filename, str directory):
cdef UploadFileData upload_file_data = UploadFileData(content, filename, directory)
cdef RemoteCommand upload_resp = self._send_receive_command(RemoteCommand(CommandType.UPLOAD_BIG_SMALL, data=upload_file_data.serialize()))
if upload_resp.command_type == CommandType.OK:
return
return LoadResult(None, None)
elif upload_resp.command_type == CommandType.ERROR:
raise Exception(f"Error from server: {upload_resp.message}")
return LoadResult(f"Error from server: {upload_resp.message}")
else:
raise Exception(f"Unexpected response command type: {upload_resp.command_type}")
return LoadResult(f"Unexpected response command type: {upload_resp.command_type}")
cdef close(self):
cdef stop(self):
if self._socket and not self._socket.closed:
self._socket.close()
if self._context and not self._context.closed:
self._context.term()
if self._loader_context and not self._loader_context.closed:
self._loader_context.term()