From 89c8d8715c78b96efae03d0460186980ee8a0e3b Mon Sep 17 00:00:00 2001 From: Pietro Brenna Date: Thu, 19 Mar 2020 15:57:51 +0100 Subject: [PATCH] Chiamata di risposta --- driver/cose.json | 1 + driver/main.py | 3 --- driver/notifier.py | 26 +++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/driver/cose.json b/driver/cose.json index 6299184..69aef70 100644 --- a/driver/cose.json +++ b/driver/cose.json @@ -8,4 +8,5 @@ "queue_id": "queueObject", "thr": "threadObject", "port": "int" + } } diff --git a/driver/main.py b/driver/main.py index 2101469..db5c577 100644 --- a/driver/main.py +++ b/driver/main.py @@ -63,9 +63,6 @@ if __name__ == '__main__': queues_in = {} queue_command = queue.Queue() queue_out = queue.Queue() - django_addr = ("http://{}:{}/" - .format(os.getenv('DJANGO_HOST', '127.0.0.1'), - os.getenv('DJANGO_PORT'))) t_notify_django = threading.Thread(target=notifier.notifier, args=[django_addr, queue_out, logger], daemon=True) diff --git a/driver/notifier.py b/driver/notifier.py index 53c9234..7c2d90e 100644 --- a/driver/notifier.py +++ b/driver/notifier.py @@ -1,11 +1,17 @@ import requests import time +import os URL_ERR = 'tscprinter/errore/' URL_EVENT = 'tscprinter/evento/' -URL_RESP = 'tscprinter/risposta/' +URL_RESPONSE = 'tscprinter/risposta/' -def notifier(django_addr, queue_out, logger): +django_addr = ("http://{}:{}/" + .format(os.getenv('DJANGO_HOST', '127.0.0.1'), + os.getenv('DJANGO_PORT'))) + + +def notifier(queue_out, logger): logger.warning("Notifier started") while True: msg = queue_out.get(block=True) @@ -16,4 +22,18 @@ def notifier(django_addr, queue_out, logger): riuscita = True except Exception as e: time.sleep(2) - print(e) \ No newline at end of file + print(e) + + +def send_response(queue_out, ip, command, data): + resp= { + 'ip': ip, + 'comando': command, + 'dati': data + } + msg = { + 'url' : URL_RESPONSE, + 'msg': resp + } + queue_out.put(msg) +