persistent queue is persistent now
This commit is contained in:
parent
c445edf5c2
commit
f039c58bdb
@ -1,7 +1,7 @@
|
|||||||
import threading
|
import threading
|
||||||
from logger import Logger
|
from logger import Logger
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
import signal
|
||||||
|
|
||||||
class DatabaseEngine(threading.Thread):
|
class DatabaseEngine(threading.Thread):
|
||||||
singleton = None
|
singleton = None
|
||||||
@ -17,9 +17,14 @@ class DatabaseEngine(threading.Thread):
|
|||||||
self.event = threading.Event()
|
self.event = threading.Event()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
|
signal.signal(signal.SIGUSR1, self.signalHandler)
|
||||||
self.startTimer()
|
self.startTimer()
|
||||||
self.setDaemon(True)
|
self.setDaemon(True)
|
||||||
|
|
||||||
|
def signalHandler(self, signum, frame):
|
||||||
|
Logger.log("SIGUSR1 received")
|
||||||
|
self.triggerStoring()
|
||||||
|
|
||||||
def triggerStoring(self):
|
def triggerStoring(self):
|
||||||
self.event.set()
|
self.event.set()
|
||||||
|
|
||||||
|
@ -17,22 +17,42 @@ DEBUG_TO_STDOUT = True
|
|||||||
BACKGROUND = False
|
BACKGROUND = False
|
||||||
PID_FILE = "/tmp/MqttDispatcher.pid"
|
PID_FILE = "/tmp/MqttDispatcher.pid"
|
||||||
LOG_FILE = "/tmp/MqttDispatcher.log"
|
LOG_FILE = "/tmp/MqttDispatcher.log"
|
||||||
|
|
||||||
MQTT_CONFIG = {
|
MQTT_CONFIG = {
|
||||||
'host':'localhost',
|
'host':'eupenstrasse20.dynamic.hottis.de',
|
||||||
'port':1883,
|
'port':8883,
|
||||||
'tls':False,
|
'tls':True,
|
||||||
'ca':'ca.crt',
|
'ca':'ca.crt',
|
||||||
'user':'tron',
|
'user':'tron',
|
||||||
'password':'geheim123'
|
'password':'geheim123'
|
||||||
}
|
}
|
||||||
DATABASE_CONFIG = {
|
DATABASE_CONFIG = {
|
||||||
'period':300,
|
'period':3600,
|
||||||
'host':'172.16.2.17',
|
'host':'localhost',
|
||||||
'user':'smarthome',
|
'user':'smarthome',
|
||||||
'password':'smarthome123',
|
'password':'smarthome123',
|
||||||
'db':'smarthome'
|
'db':'smarthome'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#MQTT_CONFIG = {
|
||||||
|
# 'host':'localhost',
|
||||||
|
# 'port':1883,
|
||||||
|
# 'tls':False,
|
||||||
|
# 'ca':'ca.crt',
|
||||||
|
# 'user':'tron',
|
||||||
|
# 'password':'geheim123'
|
||||||
|
#}
|
||||||
|
#DATABASE_CONFIG = {
|
||||||
|
# 'period':300,
|
||||||
|
# 'host':'172.16.2.17',
|
||||||
|
# 'user':'smarthome',
|
||||||
|
# 'password':'smarthome123',
|
||||||
|
# 'db':'smarthome'
|
||||||
|
#}
|
||||||
|
|
||||||
|
QUEUE_CONFIG = {
|
||||||
|
'file':'/tmp/mqttDispatcherQueue'
|
||||||
|
}
|
||||||
|
|
||||||
if BACKGROUND:
|
if BACKGROUND:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
@ -71,7 +91,7 @@ try:
|
|||||||
mqttReader.registerParser(modbusParser)
|
mqttReader.registerParser(modbusParser)
|
||||||
Logger.log("ModbusParser started ...")
|
Logger.log("ModbusParser started ...")
|
||||||
|
|
||||||
persistentQueue = PersistentQueue()
|
persistentQueue = PersistentQueue(QUEUE_CONFIG)
|
||||||
mbusParser.setNextStage(persistentQueue)
|
mbusParser.setNextStage(persistentQueue)
|
||||||
modbusParser.setNextStage(persistentQueue)
|
modbusParser.setNextStage(persistentQueue)
|
||||||
Logger.log("PersistentQueue instantiated ...")
|
Logger.log("PersistentQueue instantiated ...")
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
from logger import Logger
|
from logger import Logger
|
||||||
import Queue
|
from persistqueue import Queue
|
||||||
|
|
||||||
class PersistentQueue(object):
|
class PersistentQueue(object):
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
super(PersistentQueue, self).__init__()
|
super(PersistentQueue, self).__init__()
|
||||||
self.queue = Queue.Queue()
|
self.queue = Queue(config['file'])
|
||||||
|
|
||||||
def execute(self, data):
|
def execute(self, data):
|
||||||
#Logger.log("PersistentQueue %s" % (str(data)))
|
Logger.log("PersistentQueue %s" % (str(data)))
|
||||||
self.queue.put_nowait(data)
|
self.queue.put_nowait(data)
|
||||||
|
|
||||||
def empty(self):
|
def empty(self):
|
||||||
return self.queue.empty()
|
return not self.queue.qsize()
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.queue.get()
|
item = self.queue.get()
|
||||||
|
self.queue.task_done()
|
||||||
|
return item
|
Loading…
x
Reference in New Issue
Block a user