From 53872a4e7623e8c67dae0c1a597e1b4c1829f55b Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 16 Jun 2016 14:25:35 +0200 Subject: [PATCH] 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 1443581d..8b2f8b4e 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(); }