Exemplo n.º 1
0
 /**
  * @param SupervisorInterface $supervisor
  * @param ConfigInterface $config
  * @throws Exception
  */
 private function bootRemoteSupervisor(SupervisorInterface $supervisor, ConfigInterface $config)
 {
     $handlers = (array) $config->get('error.supervisor.handlers');
     $default = [$this->systemError('FatalError') => 'ContainerDestroy', 'Error' => 'ContainerContinue', 'Exception' => 'ContainerContinue'];
     $plugins = (array) $config->get('error.supervisor.plugins');
     $this->bootBaseOrRemote($supervisor, $default, $handlers, $plugins);
 }
Exemplo n.º 2
0
 /**
  * @param mixed[] $params
  * @return mixed
  * @throws RejectionException
  */
 protected function command($params = [])
 {
     if (!isset($params['flags'])) {
         throw new RejectionException('Invalid params.');
     }
     return $this->runtime->manager()->destroyProcess($this->config->get('main.alias'), $params['flags'])->then(function () {
         return 'Project has been destroyed.';
     });
 }
Exemplo n.º 3
0
 /**
  * @param ConfigInterface $config
  * @param CommandFactoryInterface $factory
  * @param RuntimeInterface $runtime
  * @return CommandInterface[]
  */
 protected function appCommands(ConfigInterface $config, CommandFactoryInterface $factory, RuntimeInterface $runtime)
 {
     $cmds = (array) $config->get('command.commands');
     $commands = [];
     foreach ($cmds as $name => $command) {
         $commands[$name] = $factory->create($command, [['runtime' => $runtime]]);
     }
     return $commands;
 }
Exemplo n.º 4
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ConfigInterface $config
  */
 private function registerRuntimeSupervision(RuntimeInterface $runtime, ChannelCompositeInterface $composite, ConfigInterface $config)
 {
     $timerCollection = new TimerCollection();
     $channel = $composite->bus('slave');
     $keepalive = $config->get('core.tolerance.child.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->loop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
             $timerCollection->removeTimer($alias);
             $runtime->fail(new ChildUnresponsiveException("Child runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
         });
         $timerCollection->addTimer($alias, $timer);
     });
     $channel->on('connect', function ($alias) use($timerCollection) {
         if (($timer = $timerCollection->getTimer($alias)) !== null) {
             $timer->cancel();
             $timerCollection->removeTimer($alias);
         }
     });
     $channel = $composite->bus('master');
     $keepalive = $config->get('core.tolerance.parent.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->loop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
             $timerCollection->removeTimer($alias);
             $runtime->fail(new ParentUnresponsiveException("Parent runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
         });
         $timerCollection->addTimer($alias, $timer);
     });
     $channel->on('connect', function ($alias) use($timerCollection) {
         if (($timer = $timerCollection->getTimer($alias)) !== null) {
             $timer->cancel();
             $timerCollection->removeTimer($alias);
         }
     });
 }
Exemplo n.º 5
0
 /**
  * @param CoreInterface $core
  * @param ConfigInterface $config
  * @param string $level
  * @param int $loggerLevel
  * @return HandlerInterface
  */
 private function createHandler(CoreInterface $core, ConfigInterface $config, $level, $loggerLevel)
 {
     $factory = new LoggerFactory();
     $formatter = $factory->createFormatter('LineFormatter', [$config->get('log.messagePattern'), $config->get('log.datePattern'), true]);
     $filePermission = $config->get('log.filePermission');
     $fileLocking = (bool) $config->get('log.fileLocking');
     $filePath = $config->get('log.filePattern');
     $loggerHandler = $factory->createHandler('StreamHandler', [$this->filePath($filePath, $level), $loggerLevel, false, $filePermission, $fileLocking]);
     $loggerHandler->setFormatter($formatter);
     return $loggerHandler;
 }
Exemplo n.º 6
0
 /**
  * @param mixed[] $params
  * @return mixed
  * @throws RejectionException
  */
 protected function command($params = [])
 {
     return $this->runtime->manager()->startProcess($this->config->get('main.alias'))->then(function () {
         return 'Project has been started.';
     });
 }
Exemplo n.º 7
0
 /**
  * @param ConfigInterface $config
  * @param ConfigInterface $current
  */
 private function addConfig(ConfigInterface $config, ConfigInterface $current)
 {
     $dirs = (array) $current->get('config.dirs');
     foreach ($dirs as $dir) {
         $this->addConfigByPath($current, $dir);
     }
     if ($current->exists('config.mode')) {
         $config->setOverwriteHandler($this->getOverwriteHandler($config, $current->get('config.mode')));
     }
     $config->merge($current->all());
 }
Exemplo n.º 8
0
 /**
  * @param mixed[] $params
  * @return mixed
  * @throws RejectionException
  */
 protected function command($params = [])
 {
     $req = new Request($this->channel, $this->config->get('main.alias'), new RuntimeCommand('arch:status'));
     return $req->call();
 }
Exemplo n.º 9
0
 /**
  * @param string $key
  * @return string
  */
 public function getEnv($key)
 {
     return $this->config->get('core.' . $key);
 }