diff options
Diffstat (limited to 'library/Director/Daemon/DeploymentChecker.php')
-rw-r--r-- | library/Director/Daemon/DeploymentChecker.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/library/Director/Daemon/DeploymentChecker.php b/library/Director/Daemon/DeploymentChecker.php new file mode 100644 index 0000000..82d6d05 --- /dev/null +++ b/library/Director/Daemon/DeploymentChecker.php @@ -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(); + } +} |