|
|
@ -28,24 +28,24 @@ logging_handler.setFormatter(logging_formatter) |
|
|
|
root.addHandler(logging_handler) |
|
|
|
root.addHandler(logging_handler) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def handle_task(payload: str): |
|
|
|
async def handle_task(task: object): |
|
|
|
try: |
|
|
|
try: |
|
|
|
task = json.loads(payload) |
|
|
|
|
|
|
|
logger.info("Command is OK") |
|
|
|
logger.info("Command is OK") |
|
|
|
|
|
|
|
|
|
|
|
response_task_payload = json.dumps({ |
|
|
|
response_task_payload = { |
|
|
|
'_taskId': task['_taskId'], |
|
|
|
'_taskId': task['_taskId'], |
|
|
|
'task': task['type'], |
|
|
|
'task': task['type'], |
|
|
|
'analyticUnitId': task['analyticUnitId'], |
|
|
|
'analyticUnitId': task['analyticUnitId'], |
|
|
|
'status': "in progress" |
|
|
|
'status': "IN_PROGRESS" |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message = services.server_service.ServerMessage('TASK_RESULT', response_task_payload) |
|
|
|
message = services.server_service.ServerMessage('TASK_RESULT', response_task_payload) |
|
|
|
|
|
|
|
|
|
|
|
await server_service.send_message(message) |
|
|
|
await server_service.send_message(message) |
|
|
|
|
|
|
|
|
|
|
|
res = await worker.do_task(task) |
|
|
|
res = await worker.do_task(task) |
|
|
|
res['_taskId'] = task['_taskId'] |
|
|
|
res['_taskId'] = task['_taskId'] |
|
|
|
|
|
|
|
|
|
|
|
await server_service.send_message(json.dumps(res)) |
|
|
|
await server_service.send_message(json.dumps(res)) |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
@ -53,10 +53,9 @@ async def handle_task(payload: str): |
|
|
|
|
|
|
|
|
|
|
|
async def handle_message(message: services.ServerMessage): |
|
|
|
async def handle_message(message: services.ServerMessage): |
|
|
|
payload = None |
|
|
|
payload = None |
|
|
|
if message.payload is not None: |
|
|
|
if message.method == 'TASK': |
|
|
|
payload = json.loads(message.payload) |
|
|
|
await handle_task(message.payload) |
|
|
|
if message.method == 'task': |
|
|
|
|
|
|
|
await handle_task(payload) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_services(): |
|
|
|
def init_services(): |
|
|
|
logger.info("Starting services...") |
|
|
|
logger.info("Starting services...") |
|
|
@ -70,7 +69,7 @@ def init_services(): |
|
|
|
return server_service, data_service |
|
|
|
return server_service, data_service |
|
|
|
|
|
|
|
|
|
|
|
async def app_loop(): |
|
|
|
async def app_loop(): |
|
|
|
server_service.handle_loop() |
|
|
|
await server_service.handle_loop() |
|
|
|
# await asyncio.gather(server_service.handle_loop(), test_file_save()) |
|
|
|
# await asyncio.gather(server_service.handle_loop(), test_file_save()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|