[icinga-checkins] icinga.org: icingaweb2-module-director/master: JobsCommand: stop running after one day or...

git at icinga.org git at icinga.org
Thu Jun 23 16:12:01 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 4cdf549afb63e4578a86855432c95a04133553b8
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=4cdf549afb63e4578a86855432c95a04133553b8

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Jun 23 16:11:28 2016 +0200

JobsCommand: stop running after one day or...

...when more than 100MB of memory are still in use after the last job
execution.

---

 application/clicommands/JobsCommand.php |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/application/clicommands/JobsCommand.php b/application/clicommands/JobsCommand.php
index 24b7929..ff64f92 100644
--- a/application/clicommands/JobsCommand.php
+++ b/application/clicommands/JobsCommand.php
@@ -32,8 +32,23 @@ class JobsCommand extends Command
 
     protected function runforever()
     {
+        // We'll terminate ourselves after 24h for now:
+        $runUnless = time() + 86400;
+
+        // We'll exit in case more than 100MB of memory are still in use
+        // after the last job execution:
+        $maxMem = 100 * 1024 * 1024;
+
         while (true) {
             $this->runAllPendingJobs();
+            if (memory_get_usage() > $maxMem) {
+                exit(0);
+            }
+
+            if (time() > $runUnless) {
+                exit(0);
+            }
+
             sleep(2);
         }
     }



More information about the icinga-checkins mailing list