aggiunto notifier e comandi
parent
a0da94ea88
commit
c29081e4c1
|
|
@ -13,7 +13,7 @@ import sys
|
|||
import logging
|
||||
import os
|
||||
from waitress import serve
|
||||
from driver import tsc_manager
|
||||
from driver import tsc_manager, notifier
|
||||
|
||||
#inizializza ascoltatore di Flask
|
||||
app = Flask(__name__)
|
||||
|
|
@ -66,14 +66,14 @@ if __name__ == '__main__':
|
|||
django_addr = ("http://{}:{}/"
|
||||
.format(os.getenv('DJANGO_HOST', '127.0.0.1'),
|
||||
os.getenv('DJANGO_PORT')))
|
||||
#t_notify_django = threading.Thread(target=notify_django.notifier,
|
||||
# args=[django_addr, queue_out, logger],
|
||||
# daemon=True)
|
||||
#t_notify_django.start()
|
||||
t_print = threading.Thread(target=tsc_manager.main,
|
||||
t_notify_django = threading.Thread(target=notifier.notifier,
|
||||
args=[django_addr, queue_out, logger],
|
||||
daemon=True)
|
||||
t_notify_django.start()
|
||||
t_manager = threading.Thread(target=tsc_manager.main,
|
||||
args=[queues_in, queue_out, queue_command, logger],
|
||||
daemon=True)
|
||||
t_print.start()
|
||||
t_manager.start()
|
||||
listen = "{}:{}".format(os.getenv("MARKOPRINTER_DRIVER_HOST"),
|
||||
os.getenv("MARKOPRINTER_DRIVER_PORT"))
|
||||
serve(app, listen=listen)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import requests
|
||||
import time
|
||||
|
||||
def notifier(django_addr, queue_out, logger):
|
||||
logger.warning("Notifier started")
|
||||
while True:
|
||||
msg = queue_out.get(block=True)
|
||||
riuscita = False
|
||||
while not riuscita:
|
||||
try:
|
||||
requests.post(django_addr+msg['url'], json=msg['msg'])
|
||||
riuscita = True
|
||||
except Exception as e:
|
||||
time.sleep(2)
|
||||
print(e)
|
||||
|
|
@ -9,13 +9,13 @@ Created on 19 mar 2020
|
|||
import threading, socket, sys, queue, logging
|
||||
|
||||
Q_TIMEOUT = 2
|
||||
URL_ERR = 'tscprinter/errore/'
|
||||
URL_EVENT = 'tscprinter/evento/'
|
||||
|
||||
def stampante(q_in, q_out, ip, ):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
#lancia i thread, uno per stampante
|
||||
def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger: logging.getLogger):
|
||||
queue_ip_map={}
|
||||
|
|
@ -30,11 +30,15 @@ def main(q_in :queue.Queue, q_out :queue.Queue, q_comm: queue.Queue, logger: log
|
|||
try:
|
||||
comando = q_comm.get(block=True, timeout=Q_TIMEOUT)
|
||||
if comando['name'] == "CONNETTI":
|
||||
pass
|
||||
elif comando['name'] == "DISCONNETTI":
|
||||
pass
|
||||
else:
|
||||
out
|
||||
q_out.put({'url':URL_ERR,
|
||||
'msg':{'error':'comando inesistente'}
|
||||
})
|
||||
logger.error("Comando non Trovato")
|
||||
except Empty:
|
||||
except queue.Empty:
|
||||
logger.error("Coda comandi vuota")
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue