[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorJob: really run jobs

git at icinga.org git at icinga.org
Thu Jun 16 15:09:52 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Jun 16 14:25:35 2016 +0200

DirectorJob: really run jobs

---

 library/Director/Objects/DirectorJob.php |   29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/library/Director/Objects/DirectorJob.php b/library/Director/Objects/DirectorJob.php
index 1443581..8b2f8b4 100644
--- a/library/Director/Objects/DirectorJob.php
+++ b/library/Director/Objects/DirectorJob.php
@@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects;
 
 use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
 use Icinga\Module\Director\Hook\JobHook;
+use Exception;
 
 class DirectorJob extends DbObjectWithSettings
 {
@@ -45,7 +46,31 @@ class DirectorJob extends DbObjectWithSettings
 
     public function run()
     {
-        $this->job()->setDefinition($this)->run();
+        $job = $this->job()->setDefinition($this);
+        $this->ts_last_attempt = date('Y-m-d H:i:s');
+
+        try {
+            $job->run();
+            $this->last_attempt_succeeded = 'y';
+        } catch (Exception $e) {
+            $this->ts_last_error = date('Y-m-d H:i:s');
+            $this->last_error_message = $e->getMessage();
+            $this->last_attempt_succeeded = 'n';
+        }
+
+        if ($this->hasBeenModified()) {
+            $this->store();
+        }
+    }
+
+    public function shouldRun()
+    {
+        return (! $this->hasBeenDisabled()) && $this->isPending();
+    }
+
+    public function hasBeenDisabled()
+    {
+        return $this->disabled === 'y';
     }
 
     public function isPending()
@@ -54,7 +79,7 @@ class DirectorJob extends DbObjectWithSettings
             return $this->isWithinTimeperiod();
         }
 
-        if (strtotime($this->unixts_last_attempt) + $this->run_interval < time()) {
+        if (strtotime($this->ts_last_attempt) + $this->run_interval < time()) {
             return $this->isWithinTimeperiod();
         }
 



More information about the icinga-checkins mailing list