[Piuparts-commits] [SCM] piuparts git repository branch, develop, updated. 0.45-102-g4c48ac2

Andreas Beckmann debian at abeckmann.de
Fri Aug 3 08:51:59 UTC 2012


The following commit has been merged in the develop branch:
commit a90794946135b8adc8606f86ada0cf250231713f
Author: Andreas Beckmann <debian at abeckmann.de>
Date:   Sun Jul 22 13:47:29 2012 +0200

    p-m: implement 'idle' command
    
    Returns number of seconds before the slave should retry the section
    or 0 if not known to be idle. Skew the idle time a bit to avoid
    multiple slaves connecting at the same time.
    
    Should be issued after "recycle" and log submission commands,
    but before "reserve" or "status".
    
    Allows to skip expensive package database initialization
    (downloading and parsing Packages, computing package states).
    
    Signed-off-by: Andreas Beckmann <debian at abeckmann.de>

diff --git a/README.txt b/README.txt
index 2865296..7f9aac4 100644
--- a/README.txt
+++ b/README.txt
@@ -339,6 +339,20 @@ command. It will return "error" if no more logfiles are marked
 for rechecking or the command is issued too late.
 
 ----
+Command: idle
+Success: ok <int>
+----
+Slave asks master whether it remembers having no packages
+available at a previous "reserve" command. Returns 0 (not known
+to be idle or timeout expired) or the number of seconds until
+the master wants to recompute the package state. This command
+should be given after "recycle" and logfile submission, but
+before "reserve" or "status" commands. If the slave closes the
+connection without issuing a "reserve" or "status" command, the
+expensive Packages file parsing and status computation will be
+skipped.
+
+----
 Command: reserve
 Success: ok <packagename> <packageversion>
 Failure: error
diff --git a/debian/changelog b/debian/changelog
index ea4cddf..ed2b41b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -40,6 +40,11 @@ piuparts (0.46) UNRELEASED; urgency=low
     - Add "recycle" command to enter logfile recycling mode (needs to be
       issued before "status" or "reserve").
     - Remember idle state by creating stamp files.
+    - Add "idle" command to check a remembered idle status before trying to
+      "reserve" packages (avoid package state computation).  Idle status (i.e.
+      no packages available for "reserve") will be remembered for an hour, but
+      any log modification (submission, deletion, marking for recycling) will
+      clear the idle status.
   * piuparts-slave.py:
     - Fix stopping the currently running test (Ctrl-C Ctrl-C).
     - Handle master communication exceptions while sending logs or reserving
diff --git a/piuparts-master.py b/piuparts-master.py
index c4257d6..6b0cec1 100644
--- a/piuparts-master.py
+++ b/piuparts-master.py
@@ -29,6 +29,7 @@ import ConfigParser
 import os
 import fcntl
 import time
+import random
 
 import piupartslib
 from piupartslib.packagesdb import LogfileExists
@@ -122,6 +123,7 @@ class Master(Protocol):
         Protocol.__init__(self, input, output)
         self._commands = {
             "recycle": self._recycle,
+            "idle": self._idle,
             "status": self._status,
             "reserve": self._reserve,
             "unreserve": self._unreserve,
@@ -171,6 +173,18 @@ class Master(Protocol):
             open(self._idle_stamp, "w").close()
             os.utime(self._idle_stamp, (-1, self._binary_db._stamp))
 
+    def _get_idle_status(self):
+        """ Returns number of seconds a cached idle status is still valid, or 0 if not known to be idle. """
+        if not os.path.exists(self._idle_stamp):
+            return 0
+        stamp_mtime = os.path.getmtime(self._idle_stamp)
+        ttl = stamp_mtime + 3600 - time.time()
+        if ttl <= 0:
+            return 0  # stamp expired
+        if stamp_mtime < self._binary_db.get_mtime():
+            return 0  # stamp outdated
+        return ttl + random.randrange(120)
+
 
     def do_transaction(self):
         line = self._readline()
@@ -202,6 +216,10 @@ class Master(Protocol):
         else:
             self._short_response("error")
 
+    def _idle(self, command, args):
+        self._check_args(0, command, args)
+        self._short_response("ok", "%d" % self._get_idle_status())
+
     def _status(self, command, args):
         self._check_args(0, command, args)
         self._init_db()

-- 
piuparts git repository



More information about the Piuparts-commits mailing list