From 711b51243f5e1d2c3d683acb3a18c2e72478cc12 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 26 Nov 2008 16:16:03 +0000
Subject: [PATCH] jqueue: Log progress and load jobs one by one

By logging more information, a user can see how far it is in inspecting
the queue. This can be useful with a large number of jobs. Also, instead
of loading all jobs in one go, load only the list of job IDs and then
load jobs one by one.

Reviewed-by: ultrotter
---
 lib/jqueue.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/jqueue.py b/lib/jqueue.py
index cc988964c..c6442f571 100644
--- a/lib/jqueue.py
+++ b/lib/jqueue.py
@@ -511,7 +511,20 @@ class JobQueue(object):
       # we're still doing our work.
       self.acquire()
       try:
-        for job in self._GetJobsUnlocked(None):
+        logging.info("Inspecting job queue")
+
+        all_job_ids = self._GetJobIDsUnlocked()
+        lastinfo = time.time()
+        for idx, job_id in enumerate(all_job_ids):
+          # Give an update every 1000 jobs or 10 seconds
+          if idx % 1000 == 0 or time.time() >= (lastinfo + 10.0):
+            jobs_count = len(all_job_ids)
+            logging.info("Job queue inspection: %d/%d (%0.1f %%)",
+                         idx, jobs_count, 100.0 * (idx + 1) / jobs_count)
+            lastinfo = time.time()
+
+          job = self._LoadJobUnlocked(job_id)
+
           # a failure in loading the job can cause 'None' to be returned
           if job is None:
             continue
@@ -530,6 +543,8 @@ class JobQueue(object):
                 op.result = "Unclean master daemon shutdown"
             finally:
               self.UpdateJobUnlocked(job)
+
+        logging.info("Job queue inspection finished")
       finally:
         self.release()
     except:
-- 
GitLab