Explorar el Código

Use stopwaitsecs and startretrysecs.

Chris McDonough hace 19 años
padre
commit
603f7f91c1
Se han modificado 2 ficheros con 14 adiciones y 12 borrados
  1. 6 6
      src/supervisor/supervisord.py
  2. 8 6
      src/supervisor/tests.py

+ 6 - 6
src/supervisor/supervisord.py

@@ -190,7 +190,7 @@ class Subprocess:
     def record_spawnerr(self, msg):
         self.spawnerr = msg
         self.options.logger.critical("spawnerr: %s" % msg)
-        self.do_backoff()
+        self.do_backoff(self.config.startretrysecs)
         self.governor()
 
     def spawn(self):
@@ -255,7 +255,7 @@ class Subprocess:
                 self.options.close_fd(pipes[fdname])
             self.options.logger.info('spawned: %r with pid %s' % (pname, pid))
             self.spawnerr = None
-            self.do_backoff()
+            self.do_backoff(self.config.startretrysecs)
             self.options.pidhistory[pid] = self
             return pid
         
@@ -302,7 +302,7 @@ class Subprocess:
         """ Administrative stop """
         self.administrative_stop = 1
         self.reportstatusmsg = None
-        self.do_backoff()
+        self.do_backoff(self.config.stopwaitsecs)
         return self.kill(self.config.stopsignal)
 
     def kill(self, sig):
@@ -399,8 +399,8 @@ class Subprocess:
             self.exitstatus = es
         self.reportstatusmsg = msg
 
-    def do_backoff(self):
-        self.delay = time.time() + self.options.backofflimit
+    def do_backoff(self, seconds):
+        self.delay = time.time() + seconds
 
     def set_uid(self):
         if self.config.uid is None:
@@ -611,7 +611,7 @@ class Supervisor:
                     self.options.logger.info(
                         'killing %r (%s) with SIGKILL' % (proc.config.name,
                                                           proc.pid))
-                    proc.do_backoff()
+                    proc.do_backoff(proc.config.stopwaitsecs)
                     proc.kill(signal.SIGKILL)
         return delayprocs
 

+ 8 - 6
src/supervisor/tests.py

@@ -1344,8 +1344,8 @@ class SubprocessTests(unittest.TestCase):
         config = DummyPConfig('notthere', '/notthere', logfile='/tmp/foo')
         instance = self._makeOne(options, config)
         now = time.time()
-        instance.do_backoff()
-        self.failUnless(instance.delay >= now + options.backofflimit)
+        instance.do_backoff(3)
+        self.failUnless(instance.delay >= now + 3)
 
     def test_set_uid_no_uid(self):
         options = DummyOptions()
@@ -2012,7 +2012,7 @@ class DummyProcess:
         self.childlog = DummyLogger()
         self.logsremoved = False
         self.stop_called = False
-        self.backoff_done = False
+        self.backoff_secs = None
         self.spawned = False
         self.state = state
         self.error_at_clear = False
@@ -2039,8 +2039,8 @@ class DummyProcess:
     def kill(self, signal):
         self.killed_with = signal
 
-    def do_backoff(self):
-        self.backoff_done = True
+    def do_backoff(self, secs):
+        self.backoff_secs = secs
 
     def spawn(self):
         self.spawned = True
@@ -2066,7 +2066,8 @@ class DummyProcess:
 
 class DummyPConfig:
     def __init__(self, name, command, priority=999, autostart=True,
-                 autorestart=True, uid=None, logfile=None, logfile_backups=0,
+                 autorestart=True, startretrysecs=10,
+                 uid=None, logfile=None, logfile_backups=0,
                  logfile_maxbytes=0, log_stderr=False,
                  stopsignal=signal.SIGTERM, stopwaitsecs=10,
                  exitcodes=[0,2]):
@@ -2075,6 +2076,7 @@ class DummyPConfig:
         self.priority = priority
         self.autostart = autostart
         self.autorestart = autorestart
+        self.startretrysecs = startretrysecs
         self.uid = uid
         self.logfile = logfile
         self.logfile_backups = logfile_backups