DeploymentChecker: new Background Daemon component

fixes #2045
fixes #1988
This commit is contained in:
Thomas Gelf 2020-11-30 18:47:52 +01:00
parent 0788742387
commit 4d406621aa
4 changed files with 54 additions and 2 deletions

View File

@ -52,8 +52,7 @@ class ConfigController extends ActionController
$this->addTitle($this->translate('Deployments')); $this->addTitle($this->translate('Deployments'));
try { try {
if (DirectorDeploymentLog::hasUncollected($this->db())) { if (DirectorDeploymentLog::hasUncollected($this->db())) {
$this->setAutorefreshInterval(3); $this->setAutorefreshInterval(2);
$this->api()->collectLogFiles($this->db());
} else { } else {
$this->setAutorefreshInterval(20); $this->setAutorefreshInterval(20);
} }

View File

@ -99,6 +99,7 @@ next (will be 1.8.0)
* FIX: Daemon Logger used to not override the given log level (#2139) * FIX: Daemon Logger used to not override the given log level (#2139)
* FEATURE: Daemon: prepare for future reactphp promise versions (#2137) * FEATURE: Daemon: prepare for future reactphp promise versions (#2137)
* FEATURE: Daemon now logs that it is going to reload itself * FEATURE: Daemon now logs that it is going to reload itself
* FEATURE: Now collects the Deployment status from Icinga (#2045, #1988)
### Documentation ### Documentation
* FEATURE: We now also mention optional/indirect requirements (#2054, #2220) * FEATURE: We now also mention optional/indirect requirements (#2054, #2220)

View File

@ -87,6 +87,7 @@ class BackgroundDaemon
$this->daemonDb $this->daemonDb
->register($this->jobRunner) ->register($this->jobRunner)
->register($this->logProxy) ->register($this->logProxy)
->register(new DeploymentChecker($this->loop))
->run($this->loop); ->run($this->loop);
$this->setState('running'); $this->setState('running');
} }

View File

@ -0,0 +1,51 @@
<?php
namespace Icinga\Module\Director\Daemon;
use Exception;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\DirectorDeploymentLog;
use React\EventLoop\LoopInterface;
use function React\Promise\resolve;
class DeploymentChecker implements DbBasedComponent
{
/** @var Db */
protected $connection;
public function __construct(LoopInterface $loop)
{
$loop->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();
}
}