|
|
@ -6,7 +6,13 @@ import sys |
|
|
|
|
|
|
|
|
|
|
|
from worker import Worker |
|
|
|
from worker import Worker |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root = logging.getLogger() |
|
|
|
root = logging.getLogger() |
|
|
|
|
|
|
|
logger = logging.getLogger('SERVER') |
|
|
|
|
|
|
|
socket = None |
|
|
|
|
|
|
|
worker = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root.setLevel(logging.DEBUG) |
|
|
|
root.setLevel(logging.DEBUG) |
|
|
|
|
|
|
|
|
|
|
|
ch = logging.StreamHandler(sys.stdout) |
|
|
|
ch = logging.StreamHandler(sys.stdout) |
|
|
@ -15,25 +21,23 @@ formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)- |
|
|
|
ch.setFormatter(formatter) |
|
|
|
ch.setFormatter(formatter) |
|
|
|
root.addHandler(ch) |
|
|
|
root.addHandler(ch) |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('SERVER') |
|
|
|
|
|
|
|
socket = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handlePing(): |
|
|
|
def handle_ping(): |
|
|
|
socket.send(b'pong') |
|
|
|
socket.send(b'pong') |
|
|
|
|
|
|
|
|
|
|
|
def handleTask(text): |
|
|
|
def handle_task(text): |
|
|
|
try: |
|
|
|
try: |
|
|
|
task = json.loads(text) |
|
|
|
task = json.loads(text) |
|
|
|
logger.info("Command is OK") |
|
|
|
logger.info("Command is OK") |
|
|
|
|
|
|
|
|
|
|
|
socket.send_string(json.dumps({ |
|
|
|
socket.send_string(json.dumps({ |
|
|
|
|
|
|
|
'_taskId': task['_taskId'], |
|
|
|
'task': task['type'], |
|
|
|
'task': task['type'], |
|
|
|
'analyticUnitId': task['analyticUnitId'], |
|
|
|
'analyticUnitId': task['analyticUnitId'], |
|
|
|
'_taskId': task['_taskId'], |
|
|
|
|
|
|
|
'status': "in progress" |
|
|
|
'status': "in progress" |
|
|
|
})) |
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
res = w.do_task(task) |
|
|
|
res = worker.do_task(task) |
|
|
|
res['_taskId'] = task['_taskId'] |
|
|
|
res['_taskId'] = task['_taskId'] |
|
|
|
socket.send_string(json.dumps(res)) |
|
|
|
socket.send_string(json.dumps(res)) |
|
|
|
|
|
|
|
|
|
|
@ -42,7 +46,7 @@ def handleTask(text): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
w = Worker() |
|
|
|
worker = Worker() |
|
|
|
logger.info("Worker was started") |
|
|
|
logger.info("Worker was started") |
|
|
|
|
|
|
|
|
|
|
|
logger.info("Binding to %s ..." % config.ZEROMQ_CONNECTION_STRING) |
|
|
|
logger.info("Binding to %s ..." % config.ZEROMQ_CONNECTION_STRING) |
|
|
@ -56,9 +60,9 @@ if __name__ == "__main__": |
|
|
|
text = received_bytes.decode('utf-8') |
|
|
|
text = received_bytes.decode('utf-8') |
|
|
|
logger.info('Got message %s' % text) |
|
|
|
logger.info('Got message %s' % text) |
|
|
|
if text == 'ping': |
|
|
|
if text == 'ping': |
|
|
|
handlePing() |
|
|
|
handle_ping() |
|
|
|
logger.info('Sent pong') |
|
|
|
logger.info('Sent pong') |
|
|
|
else: |
|
|
|
else: |
|
|
|
handleTask(text) |
|
|
|
handle_task(text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|