From 00348efe3a8f1d3c49b94dfb5dabb3e9a880d6a5 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 24 Oct 2023 11:03:57 +0200 Subject: [PATCH] Don't crash when failing to connect to the database --- application/clicommands/ScheduleCommand.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/application/clicommands/ScheduleCommand.php b/application/clicommands/ScheduleCommand.php index c52e0921..fc04c44e 100644 --- a/application/clicommands/ScheduleCommand.php +++ b/application/clicommands/ScheduleCommand.php @@ -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; @@ -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( @@ -73,7 +84,7 @@ public function runAction() $runningSchedules = $schedules; - Loop::addTimer(5 * 60, $watchdog); + Loop::addTimer(60, $watchdog); }; Loop::futureTick($watchdog); }