This commit is contained in:
2020-03-19 17:40:05 +01:00
parent 1c70fce6ba
commit 7335223d68
4 changed files with 253 additions and 2 deletions
+9 -2
View File
@@ -22,6 +22,9 @@ app = Flask(__name__)
@app.route('/tscprinter/printer/<ip>/<command>', methods=['POST'])
def printer_in(ip, command):
parameters = request.get_json()
# questo prossimo mi sa che non funzia perché la funzione
# inizia a esistere quando si esegue tsc_manager.main ma poi non
# viene esportata nello scope del modulo tsc_manager
queue_id = tsc_manager.get_queue_id(ip)
if queue_id is not None and queue_id in queues_in:
queues_in[queue_id].put({'name': command, 'parameters': parameters})
@@ -32,6 +35,7 @@ def printer_in(ip, command):
@app.route('/tscprinter/gest/<command>', methods=['POST'])
def gest_in(command):
parameters = request.get_json()
# istes di sopra
queue_command = tsc_manager.get_queue_command()
if queue_command is not None:
queue_command.put({'name': command, 'parameters': parameters})
@@ -71,6 +75,9 @@ if __name__ == '__main__':
args=[queues_in, queue_out, queue_command, logger],
daemon=True)
t_manager.start()
listen = "{}:{}".format(os.getenv("MARKOPRINTER_DRIVER_HOST"),
os.getenv("MARKOPRINTER_DRIVER_PORT"))
listen = "{}:{}".format(os.getenv("TSC_PRINTER_DRIVER_HOST"),
os.getenv("TSC_PRINTER_DRIVER_PORT"))
# dico (aspettando) a django che siamo pronti a ricevere gli indirizzi
# delle stampanti
notifier.send_hello(queue_out)
serve(app, listen=listen)
+7
View File
@@ -5,6 +5,7 @@ import os
URL_ERR = 'tscprinter/errore/'
URL_EVENT = 'tscprinter/evento/'
URL_RESPONSE = 'tscprinter/risposta/'
URL_HELLO = 'tscprinter/driver_acceso/'
django_addr = ("http://{}:{}/"
.format(os.getenv('DJANGO_HOST', '127.0.0.1'),
@@ -21,6 +22,7 @@ def notifier(queue_out, logger):
requests.post(django_addr+msg['url'], json=msg['msg'])
riuscita = True
except Exception as e:
print("django irraggiungibile. aspetto 2 sec...")
time.sleep(2)
print(e)
@@ -37,3 +39,8 @@ def send_response(queue_out, ip, command, data):
}
queue_out.put(msg)
def send_hello(queue_out):
queue_out.put({
'url': URL_HELLO,
'msg': {}
})