mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
DirectorJob: add run helper, support timeperiods
This commit is contained in:
parent
c3889ee5d8
commit
fa978902c7
@ -3,9 +3,12 @@
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
||||
use Icinga\Module\Director\Hook\JobHook;
|
||||
|
||||
class DirectorJob extends DbObjectWithSettings
|
||||
{
|
||||
protected $job;
|
||||
|
||||
protected $table = 'director_job';
|
||||
|
||||
protected $keyName = 'id';
|
||||
@ -22,27 +25,65 @@ class DirectorJob extends DbObjectWithSettings
|
||||
'ts_last_attempt' => null,
|
||||
'ts_last_error' => null,
|
||||
'last_error_message' => null,
|
||||
'timeperiod_id' => null,
|
||||
);
|
||||
|
||||
protected $settingsTable = 'director_job_setting';
|
||||
|
||||
protected $settingsRemoteId = 'job_id';
|
||||
|
||||
public function job()
|
||||
{
|
||||
if ($this->job === null) {
|
||||
$class = $this->job_class;
|
||||
$this->job = new $class;
|
||||
$this->job->setDb($this->connection);
|
||||
}
|
||||
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->job()->setDefinition($this)->run();
|
||||
}
|
||||
|
||||
public function isPending()
|
||||
{
|
||||
if ($this->ts_last_attempt === null) {
|
||||
return true;
|
||||
return $this->isWithinTimeperiod();
|
||||
}
|
||||
|
||||
if (strtotime($this->unixts_last_attempt) + $this->run_interval < time()) {
|
||||
return true;
|
||||
return $this->isWithinTimeperiod();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isWithinTimeperiod()
|
||||
{
|
||||
if ($this->hasTimeperiod()) {
|
||||
if (! $this->timeperiod()->isActive()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function lastAttemptSucceeded()
|
||||
{
|
||||
return $this->last_attempt_succeeded === 'y';
|
||||
}
|
||||
|
||||
public function hasTimeperiod()
|
||||
{
|
||||
return $this->timeperiod_id !== null;
|
||||
}
|
||||
|
||||
protected function timeperiod()
|
||||
{
|
||||
return IcingaTimeperiod::load($this->timeperiod_id, $this->db);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user