icingaweb2-module-director/library/Director/Job/JobRunner.php

52 lines
1.0 KiB
PHP
Raw Normal View History

2016-04-22 09:53:59 +02:00
<?php
namespace Icinga\Module\Director\Job;
2016-06-17 13:48:35 +02:00
use Icinga\Application\Logger;
2016-04-22 09:53:59 +02:00
use Icinga\Module\Director\Db;
2016-05-25 11:48:00 +02:00
use Icinga\Module\Director\Objects\DirectorJob;
2016-04-22 09:53:59 +02:00
class JobRunner
{
public function __construct(Db $db)
{
$this->db = $db;
}
public function runPendingJobs()
{
foreach ($this->getConfiguredJobs() as $job) {
2016-06-16 14:30:34 +02:00
if ($job->shouldRun()) {
2016-06-17 13:48:35 +02:00
Logger::info('Director JobRunner is starting "%s"', $job->job_name);
2016-04-22 09:53:59 +02:00
$this->run($job);
}
}
}
2016-05-25 11:48:00 +02:00
protected function run(DirectorJob $job)
2016-04-22 09:53:59 +02:00
{
if ($this->shouldFork()) {
$this->fork($job);
} else {
2016-04-22 11:28:51 +02:00
$job->run();
2016-04-22 09:53:59 +02:00
}
}
2016-05-25 11:48:00 +02:00
protected function fork(DirectorJob $job)
2016-04-22 09:53:59 +02:00
{
$cmd = 'icingacli director job run ' . $job->id;
$output = `$cmd`;
2016-06-28 14:34:42 +02:00
// TODO: capture output
2016-04-22 09:53:59 +02:00
}
protected function shouldFork()
{
return true;
}
2016-05-25 11:48:00 +02:00
protected function getConfiguredJobs()
2016-04-22 09:53:59 +02:00
{
2016-05-25 11:48:00 +02:00
return DirectorJob::loadAll($this->db);
2016-04-22 09:53:59 +02:00
}
}