forked from zewelor/bt-mqtt-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateway.py
executable file
·45 lines (35 loc) · 1.08 KB
/
gateway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import logging
import sys
if sys.version_info < (3,4):
print("To use this script you need python 3.4 or newer! got %s" % sys.version_info)
sys.exit(1)
from logger import _LOGGER
import argparse
from workers_queue import _WORKERS_QUEUE
from config import settings
from mqtt import MqttClient
from workers_manager import WorkersManager
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true', default=False)
parsed = parser.parse_args()
if parsed.debug:
_LOGGER.setLevel(logging.DEBUG)
else:
_LOGGER.setLevel(logging.INFO)
_LOGGER.debug('Starting')
mqtt = MqttClient(settings['mqtt'])
manager = WorkersManager()
manager.register_workers(settings['manager']).start(mqtt)
running = True
try:
while running:
try:
mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
except (KeyboardInterrupt, SystemExit):
raise
except Exception as e:
_LOGGER.exception(e)
except KeyboardInterrupt:
running = False
_LOGGER.info('Exiting allowing jobs to finish. If you need force exit use kill')