2015-12-02 04:02:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Clicommands;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Cli\Command;
|
2016-06-16 14:41:02 +02:00
|
|
|
use Icinga\Module\Director\Job\JobRunner;
|
2015-12-02 04:02:45 +01:00
|
|
|
use Icinga\Module\Director\Objects\ImportSource;
|
|
|
|
use Icinga\Module\Director\Objects\SyncRule;
|
2016-02-28 16:30:11 +01:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
2015-12-02 04:02:45 +01:00
|
|
|
use Icinga\Module\Director\Import\Import;
|
|
|
|
use Icinga\Module\Director\Import\Sync;
|
|
|
|
use Icinga\Application\Benchmark;
|
2016-06-16 14:41:02 +02:00
|
|
|
use Icinga\Application\Logger;
|
2015-12-02 04:02:45 +01:00
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class JobsCommand extends Command
|
|
|
|
{
|
|
|
|
public function runAction()
|
|
|
|
{
|
2016-06-16 14:41:02 +02:00
|
|
|
$job = $this->params->shift();
|
|
|
|
if ($job) {
|
|
|
|
echo "Running (theoretically) $job\n";
|
2015-12-02 04:02:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-17 16:18:02 +02:00
|
|
|
if ($this->params->shift('forever')) {
|
2016-06-16 14:41:02 +02:00
|
|
|
$this->runforever();
|
2016-06-17 16:18:02 +02:00
|
|
|
} else {
|
|
|
|
$this->runAllPendingJobs();
|
2016-06-16 14:41:02 +02:00
|
|
|
}
|
2015-12-02 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2016-06-16 14:41:02 +02:00
|
|
|
protected function runforever()
|
2015-12-02 04:02:45 +01:00
|
|
|
{
|
2016-06-16 14:41:02 +02:00
|
|
|
while (true) {
|
|
|
|
$this->runAllPendingJobs();
|
|
|
|
sleep(2);
|
2015-12-02 04:02:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 14:41:02 +02:00
|
|
|
protected function runAllPendingJobs()
|
2015-12-02 04:02:45 +01:00
|
|
|
{
|
2016-06-16 14:41:02 +02:00
|
|
|
$jobs = new JobRunner($this->db());
|
2015-12-02 04:02:45 +01:00
|
|
|
|
2016-06-16 14:41:02 +02:00
|
|
|
try {
|
|
|
|
if ($this->hasBeenDisabled()) {
|
|
|
|
return;
|
2015-12-02 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2016-06-16 14:41:02 +02:00
|
|
|
$jobs->runPendingJobs();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
Logger::error('Director Job Error: ' . $e->getMessage());
|
|
|
|
sleep(10);
|
|
|
|
}
|
2015-12-02 04:02:45 +01:00
|
|
|
}
|
|
|
|
|
2016-06-16 14:41:02 +02:00
|
|
|
protected function hasBeenDisabled()
|
2015-12-02 04:02:45 +01:00
|
|
|
{
|
2016-06-16 14:41:02 +02:00
|
|
|
return $this->db()->getSetting('disable_all_jobs') === 'y';
|
2015-12-02 04:02:45 +01:00
|
|
|
}
|
|
|
|
}
|