Daemon: prepare for future react/promise versions

fixes #2137
This commit is contained in:
Thomas Gelf 2020-06-06 23:16:47 +02:00
parent 6cd50fb392
commit 2b0c9f9dd2
5 changed files with 16 additions and 13 deletions

View File

@ -29,6 +29,9 @@ next (will be 1.8.0)
### REST API ### REST API
* FEATURE: Self Service API ignores empty/missing properties (e.g. no address) * FEATURE: Self Service API ignores empty/missing properties (e.g. no address)
### Background Daemon
* FEATURE: Daemon: prepare for future reactphp promise versions (#2137)
### Internals ### Internals
* FEATURE: Property Modifiers are now able to clone rows (#2060) * FEATURE: Property Modifiers are now able to clone rows (#2060)
* FIX: typo in DeploymentHook::onSuccessfulDump() has been fixed (#2069) * FIX: typo in DeploymentHook::onSuccessfulDump() has been fixed (#2069)

View File

@ -11,10 +11,10 @@ use Icinga\Module\Director\Db\Migrations;
use ipl\Stdlib\EventEmitter; use ipl\Stdlib\EventEmitter;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\Promise\Deferred; use React\Promise\Deferred;
use React\Promise\FulfilledPromise;
use React\Promise\RejectedPromise;
use RuntimeException; use RuntimeException;
use SplObjectStorage; use SplObjectStorage;
use function React\Promise\reject;
use function React\Promise\resolve;
class DaemonDb class DaemonDb
{ {
@ -110,7 +110,7 @@ class DaemonDb
$this->emitStatus('no configuration'); $this->emitStatus('no configuration');
$this->dbConfig = $config; $this->dbConfig = $config;
return new FulfilledPromise(); return resolve();
} else { } else {
$this->emitStatus('configuration loaded'); $this->emitStatus('configuration loaded');
$this->dbConfig = $config; $this->dbConfig = $config;
@ -123,7 +123,7 @@ class DaemonDb
{ {
if ($this->connection !== null) { if ($this->connection !== null) {
Logger::error('Trying to establish a connection while being connected'); Logger::error('Trying to establish a connection while being connected');
return new RejectedPromise(); return reject();
} }
$callback = function () use ($config) { $callback = function () use ($config) {
$this->reallyEstablishConnection($config); $this->reallyEstablishConnection($config);
@ -241,7 +241,7 @@ class DaemonDb
} }
} }
return new FulfilledPromise(); return resolve();
} }
/** /**
@ -250,7 +250,7 @@ class DaemonDb
public function disconnect() public function disconnect()
{ {
if (! $this->connection) { if (! $this->connection) {
return new FulfilledPromise(); return resolve();
} }
if ($this->pendingDisconnect) { if ($this->pendingDisconnect) {
return $this->pendingDisconnect->promise(); return $this->pendingDisconnect->promise();

View File

@ -9,8 +9,8 @@ use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\DirectorJob; use Icinga\Module\Director\Objects\DirectorJob;
use React\ChildProcess\Process; use React\ChildProcess\Process;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\Promise\FulfilledPromise;
use React\Promise\Promise; use React\Promise\Promise;
use function React\Promise\resolve;
class JobRunner implements DbBasedComponent class JobRunner implements DbBasedComponent
{ {
@ -74,7 +74,7 @@ class JobRunner implements DbBasedComponent
} }
$this->timer = $this->loop->addPeriodicTimer($this->checkInterval, $check); $this->timer = $this->loop->addPeriodicTimer($this->checkInterval, $check);
return new FulfilledPromise(); return resolve();
} }
/** /**

View File

@ -4,7 +4,7 @@ namespace Icinga\Module\Director\Daemon;
use Exception; use Exception;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use React\Promise\FulfilledPromise; use function React\Promise\resolve;
class LogProxy implements DbBasedComponent class LogProxy implements DbBasedComponent
{ {
@ -39,7 +39,7 @@ class LogProxy implements DbBasedComponent
$this->connection = $connection; $this->connection = $connection;
$this->db = $connection->getDbAdapter(); $this->db = $connection->getDbAdapter();
return new FulfilledPromise(); return resolve();
} }
/** /**
@ -50,7 +50,7 @@ class LogProxy implements DbBasedComponent
$this->connection = null; $this->connection = null;
$this->db = null; $this->db = null;
return new FulfilledPromise(); return resolve();
} }
public function log($severity, $message) public function log($severity, $message)

View File

@ -8,7 +8,7 @@ use ipl\Stdlib\EventEmitter;
use React\ChildProcess\Process; use React\ChildProcess\Process;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\Promise\Deferred; use React\Promise\Deferred;
use React\Promise\FulfilledPromise; use function React\Promise\resolve;
class ProcessList class ProcessList
{ {
@ -60,7 +60,7 @@ class ProcessList
public function killOrTerminate($timeout = 5) public function killOrTerminate($timeout = 5)
{ {
if ($this->processes->count() === 0) { if ($this->processes->count() === 0) {
return new FulfilledPromise(); return resolve();
} }
$deferred = new Deferred(); $deferred = new Deferred();
$killTimer = $this->loop->addTimer($timeout, function () use ($deferred) { $killTimer = $this->loop->addTimer($timeout, function () use ($deferred) {