DirectorJob: really run jobs

This commit is contained in:
Thomas Gelf 2016-06-16 14:25:35 +02:00
parent 2d8d7af051
commit 53872a4e76
1 changed files with 27 additions and 2 deletions

View File

@ -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();
}