From f7a63cefaf0fd3fc0b626b69b91a9e72265ed24f Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 9 Jul 2018 13:47:51 +0300 Subject: [PATCH] small refactoring --- analytics/server.py | 22 +++++++++++++--------- server/src/services/analytics_service.ts | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/analytics/server.py b/analytics/server.py index 3416ee2..6636546 100644 --- a/analytics/server.py +++ b/analytics/server.py @@ -6,7 +6,13 @@ import sys from worker import Worker + root = logging.getLogger() +logger = logging.getLogger('SERVER') +socket = None +worker = None + + root.setLevel(logging.DEBUG) ch = logging.StreamHandler(sys.stdout) @@ -15,25 +21,23 @@ formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)- ch.setFormatter(formatter) root.addHandler(ch) -logger = logging.getLogger('SERVER') -socket = None -def handlePing(): +def handle_ping(): socket.send(b'pong') -def handleTask(text): +def handle_task(text): try: task = json.loads(text) logger.info("Command is OK") socket.send_string(json.dumps({ + '_taskId': task['_taskId'], 'task': task['type'], 'analyticUnitId': task['analyticUnitId'], - '_taskId': task['_taskId'], 'status': "in progress" })) - res = w.do_task(task) + res = worker.do_task(task) res['_taskId'] = task['_taskId'] socket.send_string(json.dumps(res)) @@ -42,7 +46,7 @@ def handleTask(text): if __name__ == "__main__": - w = Worker() + worker = Worker() logger.info("Worker was started") logger.info("Binding to %s ..." % config.ZEROMQ_CONNECTION_STRING) @@ -56,9 +60,9 @@ if __name__ == "__main__": text = received_bytes.decode('utf-8') logger.info('Got message %s' % text) if text == 'ping': - handlePing() + handle_ping() logger.info('Sent pong') else: - handleTask(text) + handle_task(text) diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 38acbfb..d9752e0 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -42,7 +42,7 @@ export class AnalyticsService { this._requester.close(); } - public get ready() { return this._ready; } + public get ready(): boolean { return this._ready; } private async _initConnection() { this._requester = zmq.socket('pair');