From c983d64fe6da572e817ad95b0ed8d8bd14e32ba8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 26 Jun 2026 11:13:27 +0200 Subject: [PATCH] Add daemon Promise cleanup compatibility helper ReactPHP Promise v2 exposes cleanup through always(), while v3 exposes it through finally(). Use a small daemon helper so check-plugin shutdown registration works with both dependency branches. --- library/Vspheredb/CheckPluginHelper.php | 20 ++++++++------ library/Vspheredb/Daemon/PromiseUtil.php | 28 ++++++++++++++++++++ library/Vspheredb/Monitoring/CheckPlugin.php | 23 +++++++++------- 3 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 library/Vspheredb/Daemon/PromiseUtil.php diff --git a/library/Vspheredb/CheckPluginHelper.php b/library/Vspheredb/CheckPluginHelper.php index 998c820b..b576138f 100644 --- a/library/Vspheredb/CheckPluginHelper.php +++ b/library/Vspheredb/CheckPluginHelper.php @@ -8,6 +8,7 @@ use Exception; use gipfl\Cli\Screen; use Icinga\Module\Vspheredb\Clicommands\Command; +use Icinga\Module\Vspheredb\Daemon\PromiseUtil; use Icinga\Module\Vspheredb\Data\Anonymizer; use InvalidArgumentException; use React\Promise\PromiseInterface; @@ -75,14 +76,17 @@ protected function run($callable) } if ($result instanceof PromiseInterface) { - $result->then(function () { - // All done - }, function (Exception $e) { - $this->addProblem('UNKNOWN', $e->getMessage()); - $this->showOptionalTrace($e); - })->finally(function () { - $this->shutdown(); - }); + PromiseUtil::finally( + $result->then(function () { + // All done + }, function (Exception $e) { + $this->addProblem('UNKNOWN', $e->getMessage()); + $this->showOptionalTrace($e); + }), + function () { + $this->shutdown(); + } + ); } else { $this->shutdown(); } diff --git a/library/Vspheredb/Daemon/PromiseUtil.php b/library/Vspheredb/Daemon/PromiseUtil.php new file mode 100644 index 00000000..e3b3b8bd --- /dev/null +++ b/library/Vspheredb/Daemon/PromiseUtil.php @@ -0,0 +1,28 @@ +finally($callback); + } + + return $promise->always($callback); + } +} diff --git a/library/Vspheredb/Monitoring/CheckPlugin.php b/library/Vspheredb/Monitoring/CheckPlugin.php index 69f11b7e..13c01a30 100644 --- a/library/Vspheredb/Monitoring/CheckPlugin.php +++ b/library/Vspheredb/Monitoring/CheckPlugin.php @@ -5,6 +5,8 @@ namespace Icinga\Module\Vspheredb\Monitoring; +use Icinga\Module\Vspheredb\Daemon\PromiseUtil; + class CheckPlugin { /** @var array */ @@ -34,15 +36,18 @@ protected function run($callable) } if ($result instanceof PromiseInterface) { - $result->then(function () { - echo "as\n"; - }, function (Exception $e) { - var_dump('whut'); - $this->addProblem('UNKNOWN', $e->getMessage()); - })->finally(function () { - var_dump('Shut after res'); - $this->shutdown(); - }); + PromiseUtil::finally( + $result->then(function () { + echo "as\n"; + }, function (Exception $e) { + var_dump('whut'); + $this->addProblem('UNKNOWN', $e->getMessage()); + }), + function () { + var_dump('Shut after res'); + $this->shutdown(); + } + ); } else { $this->shutdown(); }