From: Michael Tremer Date: Thu, 29 Apr 2010 17:32:17 +0000 (+0200) Subject: Add garbage collector event. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4eaf42980fa317423f43688ccc8c941caaa5c1e7;p=oddments%2Fcappie.git Add garbage collector event. --- diff --git a/cappie/queue.py b/cappie/queue.py index cdd0090..4d22553 100644 --- a/cappie/queue.py +++ b/cappie/queue.py @@ -25,10 +25,11 @@ from threading import Thread from database import Database from errors import * +from events import * class Queue(Thread): heartbeat = 1.0 - maxitems = 100 + maxitems = 10000 def __init__(self, log): Thread.__init__(self) @@ -39,6 +40,7 @@ class Queue(Thread): self.__queue = [] self.db = Database(log) + self.lastgc = None def __len__(self): return self.length @@ -64,6 +66,8 @@ class Queue(Thread): time.sleep(self.heartbeat) continue + self._checkGc() + event = self.__queue.pop(0) self.log.debug("Processing queue event: %s" % event) try: @@ -80,3 +84,8 @@ class Queue(Thread): # Wait until queue handled all events self.join() + + def _checkGc(self): + if not self.lastgc or self.lastgc <= (time.time() - DB_GC_INTERVAL): + self.add(EventGarbageCollector(self.db, self.log)) + self.lastgc = time.time()