/** * @param \Thruway\ClientSession $session * @param $Uri * @throws \Exception * @return \React\Promise\Promise */ public function unregister(ClientSession $session, $Uri) { // TODO: maybe add an option to wait for pending calls to finish $registration = null; foreach ($this->registrations as $k => $r) { if (isset($r['procedure_name'])) { if ($r['procedure_name'] == $Uri) { $registration =& $this->registrations[$k]; break; } } } if ($registration === null) { throw new \Exception("registration not found"); } // we remove the callback from the client here // because we don't want the client to respond to any more calls $registration['callback'] = null; $futureResult = new Deferred(); if (!isset($registration["registration_id"])) { // this would happen if the registration was never acknowledged by the router // we should remove the registration and resolve any pending deferreds $this->logger->error("Registration ID is not set while attempting to unregister " . $Uri . "\n"); // reject the pending registration $registration['futureResult']->reject(); // TODO: need to figure out what to do in this off chance // We should still probably return a promise here that just rejects // there is an issue with the pending registration too that // the router may have a "REGISTERED" in transit and may still think that is // good to go - so maybe still send the unregister? } $requestId = Session::getUniqueId(); // save the request id so we can find this in the registration // list to call the deferred and remove it from the list $registration['unregister_request_id'] = $requestId; $registration['unregister_deferred'] = $futureResult; $unregisterMsg = new UnregisterMessage($requestId, $registration['registration_id']); $session->sendMessage($unregisterMsg); return $futureResult->promise(); }
/** * Launches a command as a separate process. * * The '--process-timeout' parameter can be used to set the process timeout * in seconds. Default timeout is 300 seconds. * If '--ignore-errors' parameter is specified any errors are ignored; * otherwise, an exception is raises if an error happened. * * @param string $command * @param array $params * @param LoggerInterface|null $logger * * @return integer The exit status code * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified */ public function runCommand($command, $params = [], LoggerInterface $logger = null) { $params = array_merge(['command' => $command], $params); if ($this->env && $this->env !== 'dev') { $params['--env'] = $this->env; } $ignoreErrors = false; if (array_key_exists('--ignore-errors', $params)) { $ignoreErrors = true; unset($params['--ignore-errors']); } $pb = new ProcessBuilder(); $pb->add($this->getPhp())->add($this->consoleCmdPath); if (array_key_exists('--process-timeout', $params)) { $pb->setTimeout($params['--process-timeout']); unset($params['--process-timeout']); } else { $pb->setTimeout($this->defaultTimeout); } foreach ($params as $name => $val) { $this->processParameter($pb, $name, $val); } $process = $pb->inheritEnvironmentVariables(true)->getProcess(); if (!$logger) { $logger = new NullLogger(); } $exitCode = $process->run(function ($type, $data) use($logger) { if ($type === Process::ERR) { $logger->error($data); } else { $logger->notice($data); } }); // synchronize all data caches if ($this->dataCacheManager) { $this->dataCacheManager->sync(); } $this->processResult($exitCode, $ignoreErrors, $logger); return $exitCode; }