extras-buildsys/server BuildMaster.py,1.35.2.1.4.3,1.35.2.1.4.4
Michael Schwendt
mschwendt at fedoraproject.org
Sun Sep 7 21:53:06 UTC 2008
Author: mschwendt
Update of /cvs/fedora/extras-buildsys/server
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv9457/server
Modified Files:
Tag: Plague-0_4_5
BuildMaster.py
Log Message:
add an optional periodic database ping to keep e.g. mysql connection alive
Index: BuildMaster.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/BuildMaster.py,v
retrieving revision 1.35.2.1.4.3
retrieving revision 1.35.2.1.4.4
diff -u -r1.35.2.1.4.3 -r1.35.2.1.4.4
--- BuildMaster.py 7 Sep 2008 17:05:46 -0000 1.35.2.1.4.3
+++ BuildMaster.py 7 Sep 2008 21:53:06 -0000 1.35.2.1.4.4
@@ -27,6 +27,19 @@
from plague import DebugUtils
+class PeriodicJob(): # this is reused also by external patches
+ def __init__(self, interval = 0, func = None):
+ self.interval = interval
+ self.next = time.time()
+ self.func = func
+
+ def run(self):
+ if self.interval > 0 and time.time() > self.next:
+ self.next = time.time()+self.interval;
+ if self.func:
+ self.func()
+
+
class BuildMaster(threading.Thread):
MAX_CHECKOUT_JOBS = 5
@@ -65,12 +78,23 @@
self._building_jobs = {}
self._building_jobs_lock = threading.Lock()
+ self._db_ping_interval = 3600
+ if self._cfg.has_option('Database','ping_interval'):
+ self._db_ping_interval = self._cfg.get_int('Database','ping_interval')
+ self._db_ping_job = PeriodicJob(self._db_ping_interval,self._ping_db)
+
threading.Thread.__init__(self)
self.setName("BuildMaster")
def _cleanup(self):
del self._cursor, self._dbcx
+ def _ping_db(self):
+ try:
+ self._cursor.execute('SELECT uid FROM jobs LIMIT 1')
+ except StandardError, e:
+ print "DB Error: could not access jobs database. Reason: '%s'" % e
+
def _requeue_interrupted_jobs(self):
""" Restart interrupted jobs from our db. """
self._cursor.execute("SELECT uid FROM jobs WHERE (status!='needsign' AND status!='failed' AND status!='finished') ORDER BY uid")
@@ -421,4 +445,6 @@
while not self._have_work() and time.time() <= last_time + 5:
time.sleep(0.25)
+ self._db_ping_job.run()
+
self._cleanup()
More information about the fedora-extras-commits
mailing list