/** * @param mixed[] $params * @return mixed */ protected function command($params = []) { $runtime = $this->runtime; $channel = $this->channel; $promise = Promise::doResolve(); return $promise->then(function () use($runtime) { return $runtime->manager()->getRuntimes(); })->then(function ($children) use($channel) { $promises = []; foreach ($children as $childAlias) { $req = new Request($channel, $childAlias, new RuntimeCommand('arch:status')); $promises[] = $req->call(); } return Promise::all($promises); })->then(function ($childrenData) use($runtime) { return ['parent' => $runtime->parent(), 'alias' => $runtime->alias(), 'name' => $runtime->name(), 'state' => $runtime->state(), 'children' => $childrenData]; }); }
/** * @param mixed[] $params * @return mixed */ protected function command($params = []) { $runtime = $this->runtime; $channel = $this->channel; $promise = $this->runtime->stop(); return $promise->then(function () use($runtime) { return $runtime->manager()->getRuntimes(); })->then(function ($children) use($channel) { $promises = []; foreach ($children as $childAlias) { $req = new Request($channel, $childAlias, new RuntimeCommand('arch:stop')); $promises[] = $req->call(); } return Promise::all($promises); })->then(function () { return 'Part of architecture has been stopped.'; }, function () { throw new RejectionException('Part of architecture could not be stopped.'); }); }
/** * @param int $flags * @return PromiseInterface */ public function flushRuntimes($flags = Runtime::DESTROY_KEEP) { return Promise::all([$this->flushThreads($flags), $this->flushProcesses($flags)]); }
/** * @param int $flags * @return PromiseInterface */ public function flushProcesses($flags = Runtime::DESTROY_KEEP) { $promises = []; if ($flags !== Runtime::DESTROY_KEEP) { foreach ($this->processes as $alias => $process) { $promises[] = $this->destroyProcess($alias, $flags); } } return Promise::all($promises)->always(function () { $this->processes = []; $this->updateStorage(); })->then(function () { return 'Processes storage has been flushed.'; }); }