Skip to content

Commit 0968885

Browse files
committed
Daemon: use PromiseInterface
1 parent 644338b commit 0968885

File tree

9 files changed

+32
-53
lines changed

9 files changed

+32
-53
lines changed

application/clicommands/SyncCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Icinga\Module\Eventtracker\Issue;
1010
use Icinga\Module\Eventtracker\Issues;
1111
use Icinga\Module\Eventtracker\Scom\ScomSync;
12-
use React\Promise\ExtendedPromiseInterface;
12+
13+
use React\Promise\PromiseInterface;
1314

1415
use function React\Promise\resolve;
1516

@@ -88,10 +89,9 @@ protected function runScom()
8889
}
8990

9091
/**
91-
* @return \React\Promise\FulfilledPromise
9292
* @throws \Icinga\Exception\ConfigurationError
9393
*/
94-
public function runIdo(): ExtendedPromiseInterface
94+
public function runIdo(): PromiseInterface
9595
{
9696
$ido = IdoDb::fromMonitoringModule();
9797
$sync = new IcingaCiSync(DbFactory::db(), $ido);
@@ -111,7 +111,7 @@ public function runIdo(): ExtendedPromiseInterface
111111
* @return \React\Promise\FulfilledPromise
112112
* @throws \Icinga\Exception\ConfigurationError
113113
*/
114-
public function runIdoState(): ExtendedPromiseInterface
114+
public function runIdoState(): PromiseInterface
115115
{
116116
$ido = IdoDb::fromMonitoringModule();
117117
$sync = new IcingaStateSync(DbFactory::db(), $ido);
@@ -120,7 +120,7 @@ public function runIdoState(): ExtendedPromiseInterface
120120
return resolve(null);
121121
}
122122

123-
public function runExpirations(): ExtendedPromiseInterface
123+
public function runExpirations(): PromiseInterface
124124
{
125125
$db = DbFactory::db();
126126
$issues = new Issues($db);
@@ -136,7 +136,7 @@ public function runExpirations(): ExtendedPromiseInterface
136136
return resolve(null);
137137
}
138138

139-
public function runHostlists(): ExtendedPromiseInterface
139+
public function runHostlists(): PromiseInterface
140140
{
141141
$configured = $this->Config()->getSection('director-host-lists')->toArray();
142142
if (empty($configured)) {

library/Eventtracker/Daemon/DaemonDb.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use React\EventLoop\Loop;
1717
use React\EventLoop\TimerInterface;
1818
use React\Promise\Deferred;
19-
use React\Promise\ExtendedPromiseInterface;
19+
use React\Promise\PromiseInterface;
2020
use RuntimeException;
2121
use SplObjectStorage;
2222

@@ -50,9 +50,7 @@ class DaemonDb
5050
protected ?array $dbConfig;
5151

5252
protected ?RetryUnless $pendingReconnection = null;
53-
54-
/** @var ExtendedPromiseInterface|null */
55-
protected $pendingDisconnect;
53+
protected ?PromiseInterface $pendingDisconnect = null;
5654
protected ?TimerInterface $refreshTimer = null;
5755
protected ?TimerInterface $schemaCheckTimer = null;
5856

@@ -117,7 +115,7 @@ protected function onNewConfig($config)
117115
}
118116
}
119117

120-
protected function establishConnection($config): ExtendedPromiseInterface
118+
protected function establishConnection($config): PromiseInterface
121119
{
122120
if ($this->db !== null) {
123121
$this->logger->error('Trying to establish a connection while being connected');
@@ -227,7 +225,7 @@ protected function onConnected()
227225
}
228226
}
229227

230-
protected function reconnect(): ExtendedPromiseInterface
228+
protected function reconnect(): PromiseInterface
231229
{
232230
$promise = $this->disconnect()->then(function () {
233231
return $this->connect();
@@ -236,14 +234,10 @@ protected function reconnect(): ExtendedPromiseInterface
236234
exit(1);
237235
});
238236

239-
assert($promise instanceof ExtendedPromiseInterface);
240237
return $promise;
241238
}
242239

243-
/**
244-
* @return \React\Promise\ExtendedPromiseInterface
245-
*/
246-
public function connect()
240+
public function connect(): PromiseInterface
247241
{
248242
if ($this->db === null) {
249243
if ($this->dbConfig) {
@@ -254,7 +248,7 @@ public function connect()
254248
return resolve(null);
255249
}
256250

257-
protected function stopRegisteredComponents(): ExtendedPromiseInterface
251+
protected function stopRegisteredComponents(): PromiseInterface
258252
{
259253
$pending = new Deferred();
260254
$pendingComponents = new SplObjectStorage();
@@ -273,12 +267,12 @@ protected function stopRegisteredComponents(): ExtendedPromiseInterface
273267
return $pending->promise();
274268
}
275269

276-
public function disconnect(): ExtendedPromiseInterface
270+
public function disconnect(): PromiseInterface
277271
{
278272
if (! $this->db) {
279273
return resolve(null);
280274
}
281-
if ($this->pendingDisconnect instanceof ExtendedPromiseInterface) {
275+
if ($this->pendingDisconnect instanceof PromiseInterface) {
282276
return $this->pendingDisconnect;
283277
}
284278

@@ -297,7 +291,6 @@ public function disconnect(): ExtendedPromiseInterface
297291
$this->db = null;
298292
$this->pendingDisconnect = null;
299293
});
300-
assert($pending instanceof ExtendedPromiseInterface);
301294

302295
return $pending;
303296
}

library/Eventtracker/Daemon/DbBasedComponent.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
namespace Icinga\Module\Eventtracker\Daemon;
44

5-
use gipfl\ZfDb\Adapter\Adapter as Db;
5+
use gipfl\ZfDb\Adapter\Pdo\PdoAdapter;
6+
use React\Promise\PromiseInterface;
67

78
interface DbBasedComponent
89
{
9-
/**
10-
* @param Db $db
11-
* @return \React\Promise\ExtendedPromiseInterface;
12-
*/
13-
public function initDb(Db $db);
10+
public function initDb(PdoAdapter $db): void;
1411

15-
/**
16-
* @return \React\Promise\ExtendedPromiseInterface;
17-
*/
18-
public function stopDb();
12+
public function stopDb(): PromiseInterface;
1913
}

library/Eventtracker/Daemon/IcingaCliRpc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function init()
3737
}
3838

3939
/**
40-
* @return PromiseInterface <Connection>
40+
* @return PromiseInterface<JsonRpcConnection>
4141
*/
4242
public function rpc()
4343
{

library/Eventtracker/Daemon/InputAndChannelRunner.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Icinga\Module\Eventtracker\Engine\Downtime\DowntimeRunner;
88
use Icinga\Module\Eventtracker\Engine\InputRunner;
99
use Psr\Log\LoggerInterface;
10+
use React\Promise\PromiseInterface;
1011

1112
use function React\Promise\resolve;
1213

@@ -40,10 +41,7 @@ public function getInputRunner(): ?InputRunner
4041
return $this->runner;
4142
}
4243

43-
/**
44-
* @return \React\Promise\ExtendedPromiseInterface
45-
*/
46-
public function stopDb()
44+
public function stopDb(): PromiseInterface
4745
{
4846
if ($this->runner) {
4947
$this->runner->stop();

library/Eventtracker/Daemon/JobRunner.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
use React\ChildProcess\Process;
1414
use React\EventLoop\Loop;
1515
use React\EventLoop\TimerInterface;
16-
use React\Promise\ExtendedPromiseInterface;
1716
use React\Promise\Promise;
17+
use React\Promise\PromiseInterface;
1818

1919
use function array_shift;
20-
use function React\Promise\resolve;
2120

2221
class JobRunner implements DbBasedComponent
2322
{
@@ -97,11 +96,9 @@ public function initDb(Db $db)
9796
}
9897
$this->timer = Loop::addPeriodicTimer($this->checkInterval, $check);
9998
$this->scheduleTimer = Loop::addPeriodicTimer(7, $schedule); // TODO: can this be combined?
100-
101-
return resolve(null);
10299
}
103100

104-
public function stopDb(): ExtendedPromiseInterface
101+
public function stopDb(): PromiseInterface
105102
{
106103
$this->scheduledTasks = [];
107104
if ($this->timer !== null) {

library/Eventtracker/Daemon/RpcNamespace/RpcNamespaceEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
use Ramsey\Uuid\Uuid;
2121
use Ramsey\Uuid\UuidInterface;
2222
use React\Promise\Deferred;
23-
use React\Promise\ExtendedPromiseInterface;
2423
use React\Promise\PromiseInterface;
2524
use RuntimeException;
2625
use stdClass;
2726

2827
use function React\Promise\resolve;
29-
use function React\Promise\Timer\timeout;
3028

3129
class RpcNamespaceEvent implements DbBasedComponent, EventEmitterInterface
3230
{
@@ -60,7 +58,7 @@ public function __construct(
6058
$this->counters = new Counters();
6159
}
6260

63-
protected function initializeActions()
61+
protected function initializeActions(): void
6462
{
6563
$actions = (new ConfigStore($this->db, $this->logger))->loadActions(['enabled' => 'y']);
6664
/** @var Action $action */
@@ -210,7 +208,7 @@ public function initDb(Db $db): ExtendedPromiseInterface
210208
return resolve(null);
211209
}
212210

213-
public function stopDb(): ExtendedPromiseInterface
211+
public function stopDb(): PromiseInterface
214212
{
215213
$this->db = null;
216214
$this->stopActions();

library/Eventtracker/Daemon/RpcNamespace/RpcNamespaceIssue.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Psr\Log\LoggerInterface;
1212
use Ramsey\Uuid\Uuid;
1313
use Ramsey\Uuid\UuidInterface;
14-
use React\Promise\ExtendedPromiseInterface;
14+
use React\Promise\PromiseInterface;
1515
use RuntimeException;
1616

1717
use function React\Promise\resolve;
@@ -118,14 +118,12 @@ public function acknowledgeRequest(string $issueUuid, string $owner, ?string $ti
118118
return true;
119119
}
120120

121-
public function initDb(Db $db): ExtendedPromiseInterface
121+
public function initDb(PdoAdapter $db): void
122122
{
123123
$this->db = $db;
124-
125-
return resolve(null);
126124
}
127125

128-
public function stopDb(): ExtendedPromiseInterface
126+
public function stopDb(): PromiseInterface
129127
{
130128
$this->db = null;
131129

library/Eventtracker/Engine/Action/ActionHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public static function processIssue(
4646
ActionHistory::persist($action, $issue, false, (string) $reason, $db);
4747
});
4848
}
49-
50-
return all($promises);
49+
timeout(all($promises), 15)->then(null, function (Throwable $reason) use ($logger) {
50+
$logger->error($reason);
51+
});
5152
}
5253

5354
protected static function isSkippedByProblemHandling(Issue $issue, Adapter $db): bool
@@ -76,7 +77,7 @@ protected static function getProblemHandling(Adapter $db): array
7677
return self::$problemHandling;
7778
}
7879

79-
protected static function forgetProblemHandling()
80+
protected static function forgetProblemHandling(): void
8081
{
8182
self::$problemHandling = null;
8283
}

0 commit comments

Comments
 (0)