changeset 312:2d6915bce473

Rework the packager mainloop. it's a bit simpler now and stopping should be more reliable.
author Bernhard Herzog <bh@intevation.de>
date Wed, 02 Dec 2009 16:31:48 +0000
parents d0acc0614de5
children 170c8be38d84
files treepkg/packager.py
diffstat 1 files changed, 16 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/packager.py	Wed Dec 02 15:37:46 2009 +0000
+++ b/treepkg/packager.py	Wed Dec 02 16:31:48 2009 +0000
@@ -617,30 +617,29 @@
         logging.info("binary packages needed as build dependencies: %s",
                      " ".join(self.needed_binaries))
 
-
     def run(self):
         """Runs the packager group indefinitely"""
         logging.info("Starting in periodic check mode."
                      "  Will check every %d seconds", self.check_interval)
-        last_check = -1
+        next_check = time.time()
         while 1:
-            now = time.time()
-            if now > last_check + self.check_interval:
+            if self.should_stop():
+                logging.info("Received stop instruction.  Stopping.")
+                return
+
+            this_check = time.time()
+            if this_check >= next_check:
+                logging.info("Next check is now")
                 if self.check_package_tracks():
                     break
-                last_check = now
-                next_check = now + self.check_interval
-                to_sleep = next_check - time.time()
-                if to_sleep > 0:
-                    logging.info("Next check at %s",
-                                 time.strftime("%Y-%m-%d %H:%M:%S",
-                                               time.localtime(next_check)))
-                    time.sleep(to_sleep)
-                else:
-                    logging.info("Next check now")
-                if self.should_stop():
-                    logging.info("Received stop instruction.  Stopping.")
-                    return
+                last_check = this_check
+                next_check = this_check + self.check_interval
+            else:
+                to_sleep = next_check - this_check
+                logging.info("Next check at %s",
+                             time.strftime("%Y-%m-%d %H:%M:%S",
+                                           time.localtime(next_check)))
+                time.sleep(to_sleep)
 
     def check_package_tracks(self):
         logging.info("Checking package tracks")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)