Add database interface to queue class.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2010 14:42:27 +0000 (16:42 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2010 14:42:27 +0000 (16:42 +0200)
cappie/queue.py

index e2d0dd6..cdd0090 100644 (file)
@@ -23,6 +23,7 @@ import time
 
 from threading import Thread
 
+from database import Database
 from errors import *
 
 class Queue(Thread):
@@ -37,6 +38,8 @@ class Queue(Thread):
                self.__running = True
                self.__queue = []
 
+               self.db = Database(log)
+
        def __len__(self):
                return self.length
 
@@ -53,6 +56,8 @@ class Queue(Thread):
        def run(self):
                self.log.debug("Started event queue")
 
+               self.db.open()
+
                while self.__running or self.__queue:
                        if not self.__queue:
                                #self.log.debug("Queue sleeping for %s seconds" % self.heartbeat)
@@ -66,6 +71,8 @@ class Queue(Thread):
                        except EventException, e:
                                self.log.error("Catched event exception: %s" % e)
 
+               self.db.close()
+
        def shutdown(self):
                self.__running = False
                self.log.debug("Shutting down queue")