[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

extras-buildsys/server UserInterface.py, 1.8, 1.9 BuildMaster.py, 1.6, 1.7



Author: dcbw

Update of /cvs/fedora/extras-buildsys/server
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv15630/server

Modified Files:
	UserInterface.py BuildMaster.py 
Log Message:
2005-06-25  Dan Williams <dcbw redhat com>

    * server/BuildMaster.py
      server/UserInterface.py
        - Make queries work again




Index: UserInterface.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/UserInterface.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UserInterface.py	24 Jun 2005 17:24:20 -0000	1.8
+++ UserInterface.py	25 Jun 2005 22:22:10 -0000	1.9
@@ -22,6 +22,7 @@
 import time
 import sys
 import os
+import copy
 import BuildMaster
 
 
@@ -118,13 +119,20 @@
 
         if len(search):
             sql = sql + search
-        self._curs.execute(sql)
-        self._dbcx.commit()
-        data = self._curs.fetchall()
+        if not len(sql):
+            return []
+
         job_list = []
-        for row in data:
-            tempX = [ item for item in row]
-            job_list.append(tempX)
+        query = BuildMaster.JobsQuery(sql)
+        self._bm.queue_query(query)
+        start_time = time.time()
+
+        # Wait for query to return from BuildMaster
+        while time.time() <= start_time + 5:
+            if query.done:
+                job_list = copy.deepcopy(query.result)
+                del query
+                break
         return job_list
 
 


Index: BuildMaster.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/BuildMaster.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BuildMaster.py	24 Jun 2005 17:24:20 -0000	1.6
+++ BuildMaster.py	25 Jun 2005 22:22:10 -0000	1.7
@@ -25,6 +25,18 @@
 import Repo
 
 
+class JobsQuery:
+    """ Wrapper class around DB query results.  Since only one
+        thread has access to the database (to work around sqlite
+        locking limitations), this object wraps requests to and
+        from the BuildMaster thread.
+    """
+    def __init__(self, query):
+        self.sql = query
+        self.done = False
+        self.result = None
+
+
 def ensure_job_db_tables(dbcx):
     """ Central routine to create the database table structure """
 
@@ -71,6 +83,9 @@
         self._status_updates = {}
         self._status_updates_lock = threading.Lock()
 
+        self._query_queue = []
+        self._query_queue_lock = threading.Lock()
+
         self.dbcx = sqlite.connect("jobdb", encoding="utf-8", timeout=3)
         self.curs = self.dbcx.cursor()
         ensure_job_db_tables(self.dbcx)
@@ -203,9 +218,55 @@
 
         self._new_queue_lock.release()
 
+    def queue_query(self, query):
+        self._query_queue_lock.acquire()
+        if query.sql:
+            self._query_queue.append(query)
+        self._query_queue_lock.release()
+
+    def _process_queries(self):
+        self._query_queue_lock.acquire()
+
+        for query in self._query_queue:
+            self.curs.execute(query.sql)
+            self.dbcx.commit()
+            data = self.curs.fetchall()
+            results = []
+            for row in data:
+                tempX = [ item for item in row ]
+                results.append(tempX)
+            query.result = results
+            query.done = True
+            self._query_queue.remove(query)
+        self._query_queue_lock.release()
+
+    def _have_work(self):
+        have_work = False
+        self._new_queue_lock.acquire()
+        if len(self._new_queue) > 0:
+            have_work = True
+        self._new_queue_lock.release()
+        if have_work:
+            return True
+
+        self._query_queue_lock.acquire()
+        if len(self._query_queue) > 0:
+            have_work = True
+        self._query_queue_lock.release()
+        if have_work:
+            return True
+
+        self._status_updates_lock.acquire()
+        if len(self._status_updates) > 0:
+            have_work = True
+        self._status_updates_lock.release()
+        if have_work:
+            return True
+
+        return False
+
     def run(self):
         while self.should_stop == False:
-
             # Write update status for jobs to the database
             self._save_job_status()
 
@@ -218,14 +279,10 @@
             # Start any new jobs
             self._start_new_jobs()
 
+            # Execute any queued queries from other threads
+            self._process_queries()
+
             last_time = time.time()
-            have_work = False
-            while not have_work and time.time() <= last_time + 5:
+            while not self._have_work() and time.time() <= last_time + 5:
                 time.sleep(0.25)
 
-                # Break out early if there's work to do
-                self._new_queue_lock.acquire()
-                if len(self._new_queue) > 0:
-                    have_work = True
-                self._new_queue_lock.release()
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]