Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash when failing to connect to the database #212

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
yhabteab marked this conversation as resolved.
Show resolved Hide resolved

$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