From 4d406621aad90ed4feb6b0677735c5987d23d16c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 30 Nov 2020 18:47:52 +0100 Subject: [PATCH] DeploymentChecker: new Background Daemon component fixes #2045 fixes #1988 --- application/controllers/ConfigController.php | 3 +- doc/82-Changelog.md | 1 + library/Director/Daemon/BackgroundDaemon.php | 1 + library/Director/Daemon/DeploymentChecker.php | 51 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 library/Director/Daemon/DeploymentChecker.php diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 863c8887..ce17642a 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -52,8 +52,7 @@ class ConfigController extends ActionController $this->addTitle($this->translate('Deployments')); try { if (DirectorDeploymentLog::hasUncollected($this->db())) { - $this->setAutorefreshInterval(3); - $this->api()->collectLogFiles($this->db()); + $this->setAutorefreshInterval(2); } else { $this->setAutorefreshInterval(20); } diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index ed90e65b..50f8fde5 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -99,6 +99,7 @@ next (will be 1.8.0) * FIX: Daemon Logger used to not override the given log level (#2139) * FEATURE: Daemon: prepare for future reactphp promise versions (#2137) * FEATURE: Daemon now logs that it is going to reload itself +* FEATURE: Now collects the Deployment status from Icinga (#2045, #1988) ### Documentation * FEATURE: We now also mention optional/indirect requirements (#2054, #2220) diff --git a/library/Director/Daemon/BackgroundDaemon.php b/library/Director/Daemon/BackgroundDaemon.php index 1fdeea31..34cc28b7 100644 --- a/library/Director/Daemon/BackgroundDaemon.php +++ b/library/Director/Daemon/BackgroundDaemon.php @@ -87,6 +87,7 @@ class BackgroundDaemon $this->daemonDb ->register($this->jobRunner) ->register($this->logProxy) + ->register(new DeploymentChecker($this->loop)) ->run($this->loop); $this->setState('running'); } diff --git a/library/Director/Daemon/DeploymentChecker.php b/library/Director/Daemon/DeploymentChecker.php new file mode 100644 index 00000000..82d6d058 --- /dev/null +++ b/library/Director/Daemon/DeploymentChecker.php @@ -0,0 +1,51 @@ +addPeriodicTimer(5, function () { + if ($db = $this->connection) { + try { + if (DirectorDeploymentLog::hasUncollected($db)) { + $db->getDeploymentEndpoint()->api()->collectLogFiles($db); + } + } catch (Exception $e) { + // Ignore eventual issues while talking to Icinga + } + } + }); + } + + /** + * @param Db $connection + * @return \React\Promise\ExtendedPromiseInterface + */ + public function initDb(Db $connection) + { + $this->connection = $connection; + + return resolve(); + } + + /** + * @return \React\Promise\ExtendedPromiseInterface + */ + public function stopDb() + { + $this->connection = null; + + return resolve(); + } +}