Skip to content

Commit

Permalink
Don't crash when failing to connect to the database
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Oct 24, 2023
1 parent 2c7d53e commit 00348ef
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions application/clicommands/ScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use DateTime;
use Exception;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Data\ResourceFactory;
use Icinga\Module\Reporting\Cli\Command;
use Icinga\Module\Reporting\Model;
use Icinga\Module\Reporting\Report;
Expand Down Expand Up @@ -37,7 +39,16 @@ public function runAction()
// Check for configuration changes every 5 minutes to make sure new jobs are scheduled, updated and deleted
// jobs are cancelled.
$watchdog = function () use (&$watchdog, $scheduler, &$runningSchedules) {
$schedules = $this->fetchSchedules();
$schedules = [];
try {
ResourceFactory::setConfig(Config::app('resources', true));
Config::module('reporting', 'config', true);

$schedules = $this->fetchSchedules();
} catch (Throwable $err) {
Logger::error('Failed to fetch report schedules from the database: %s', $err);
}

$outdated = array_diff_key($runningSchedules, $schedules);
foreach ($outdated as $schedule) {
Logger::info(
Expand Down Expand Up @@ -73,7 +84,7 @@ public function runAction()

$runningSchedules = $schedules;

Loop::addTimer(5 * 60, $watchdog);
Loop::addTimer(60, $watchdog);
};
Loop::futureTick($watchdog);
}
Expand Down

0 comments on commit 00348ef

Please sign in to comment.