Skip to content

Commit

Permalink
Don't crash when failing to connect to the database (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab authored Oct 25, 2023
2 parents 2c7d53e + a98cc22 commit ed544af
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion 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,20 @@ 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 {
// Since this is a long-running daemon, the resources or module config may change meanwhile.
// Therefore, reload the resources and module config from disk each time (at 5m intervals)
// before reconnecting to the database.
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);
Logger::debug($err->getTraceAsString());
}

$outdated = array_diff_key($runningSchedules, $schedules);
foreach ($outdated as $schedule) {
Logger::info(
Expand Down

0 comments on commit ed544af

Please sign in to comment.