2020-11-30 12:47:52 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Daemon;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use Icinga\Module\Director\Db;
|
|
|
|
|
use Icinga\Module\Director\Objects\DirectorDeploymentLog;
|
|
|
|
|
use React\EventLoop\LoopInterface;
|
2026-03-02 02:56:18 -05:00
|
|
|
use React\Promise\PromiseInterface;
|
2024-10-22 08:31:14 -04:00
|
|
|
|
2020-11-30 12:47:52 -05:00
|
|
|
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
|
2026-03-02 02:56:18 -05:00
|
|
|
*
|
|
|
|
|
* @return PromiseInterface
|
2020-11-30 12:47:52 -05:00
|
|
|
*/
|
|
|
|
|
public function initDb(Db $connection)
|
|
|
|
|
{
|
|
|
|
|
$this->connection = $connection;
|
|
|
|
|
|
2026-03-02 03:24:25 -05:00
|
|
|
return resolve(null);
|
2020-11-30 12:47:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-03-02 02:56:18 -05:00
|
|
|
* @return PromiseInterface
|
2020-11-30 12:47:52 -05:00
|
|
|
*/
|
|
|
|
|
public function stopDb()
|
|
|
|
|
{
|
|
|
|
|
$this->connection = null;
|
|
|
|
|
|
2026-03-02 03:24:25 -05:00
|
|
|
return resolve(null);
|
2020-11-30 12:47:52 -05:00
|
|
|
}
|
|
|
|
|
}
|