mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
parent
4ba2c21ce9
commit
7a95f430bf
@ -147,6 +147,14 @@ class BackgroundDaemon
|
|||||||
// TODO: level is sent but not used
|
// TODO: level is sent but not used
|
||||||
$processState->setComponentState('db', $state);
|
$processState->setComponentState('db', $state);
|
||||||
});
|
});
|
||||||
|
$db->on('schemaChange', function ($startupSchema, $dbSchema) {
|
||||||
|
Logger::info(sprintf(
|
||||||
|
"DB schema version changed. Started with %d, DB has %d. Restarting.",
|
||||||
|
$startupSchema,
|
||||||
|
$dbSchema
|
||||||
|
));
|
||||||
|
$this->reload();
|
||||||
|
});
|
||||||
|
|
||||||
$db->setConfigWatch(
|
$db->setConfigWatch(
|
||||||
$dbResourceName
|
$dbResourceName
|
||||||
|
@ -47,8 +47,15 @@ class DaemonDb
|
|||||||
/** @var Deferred|null */
|
/** @var Deferred|null */
|
||||||
protected $pendingDisconnect;
|
protected $pendingDisconnect;
|
||||||
|
|
||||||
|
/** @var \React\EventLoop\TimerInterface */
|
||||||
protected $refreshTimer;
|
protected $refreshTimer;
|
||||||
|
|
||||||
|
/** @var \React\EventLoop\TimerInterface */
|
||||||
|
protected $schemaCheckTimer;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
protected $startupSchemaVersion;
|
||||||
|
|
||||||
public function __construct(DaemonProcessDetails $details, $dbConfig = null)
|
public function __construct(DaemonProcessDetails $details, $dbConfig = null)
|
||||||
{
|
{
|
||||||
$this->details = $details;
|
$this->details = $details;
|
||||||
@ -84,6 +91,9 @@ class DaemonDb
|
|||||||
$this->refreshTimer = $loop->addPeriodicTimer(3, function () {
|
$this->refreshTimer = $loop->addPeriodicTimer(3, function () {
|
||||||
$this->refreshMyState();
|
$this->refreshMyState();
|
||||||
});
|
});
|
||||||
|
$this->schemaCheckTimer = $loop->addPeriodicTimer(15, function () {
|
||||||
|
$this->checkDbSchema();
|
||||||
|
});
|
||||||
if ($this->configWatch) {
|
if ($this->configWatch) {
|
||||||
$this->configWatch->run($this->loop);
|
$this->configWatch->run($this->loop);
|
||||||
}
|
}
|
||||||
@ -148,7 +158,8 @@ class DaemonDb
|
|||||||
if ($this->hasAnyOtherActiveInstance($connection)) {
|
if ($this->hasAnyOtherActiveInstance($connection)) {
|
||||||
throw new RuntimeException('DB is locked by a running daemon instance');
|
throw new RuntimeException('DB is locked by a running daemon instance');
|
||||||
}
|
}
|
||||||
$this->details->set('schema_version', $migrations->getLastMigrationNumber());
|
$this->startupSchemaVersion = $migrations->getLastMigrationNumber();
|
||||||
|
$this->details->set('schema_version', $this->startupSchemaVersion);
|
||||||
|
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->db = $connection->getDbAdapter();
|
$this->db = $connection->getDbAdapter();
|
||||||
@ -159,6 +170,42 @@ class DaemonDb
|
|||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function checkDbSchema()
|
||||||
|
{
|
||||||
|
if ($this->connection === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->schemaIsOutdated()) {
|
||||||
|
$this->emit('schemaChange', [
|
||||||
|
$this->getStartupSchemaVersion(),
|
||||||
|
$this->getDbSchemaVersion()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function schemaIsOutdated()
|
||||||
|
{
|
||||||
|
return $this->getStartupSchemaVersion() < $this->getDbSchemaVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getStartupSchemaVersion()
|
||||||
|
{
|
||||||
|
return $this->startupSchemaVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDbSchemaVersion()
|
||||||
|
{
|
||||||
|
if ($this->connection === null) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
'Cannot determine DB schema version without an established DB connection'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$migrations = new Migrations($this->connection);
|
||||||
|
|
||||||
|
return $migrations->getLastMigrationNumber();
|
||||||
|
}
|
||||||
|
|
||||||
protected function onConnected()
|
protected function onConnected()
|
||||||
{
|
{
|
||||||
$this->emitStatus('connected');
|
$this->emitStatus('connected');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user