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(); }