public function run() { $this->daemons = array(); foreach ($this->config['daemons'] as $config) { $config += array('argv' => array(), 'autoscale' => array()); $daemon = new PhutilDaemonHandle($this, $config['class'], $this->argv, array('log' => $this->log, 'argv' => $config['argv'], 'load' => $this->libraries, 'autoscale' => $config['autoscale'])); $daemon->setSilent(!$this->traceMode && !$this->verbose); $daemon->setTraceMemory($this->traceMemory); $this->addDaemon($daemon, $config); } $should_reload = false; while (true) { foreach ($this->modules as $module) { try { if ($module->shouldReloadDaemons()) { $should_reload = true; } } catch (Exception $ex) { phlog($ex); } } if ($should_reload) { $this->didReceiveReloadSignal(SIGHUP); $should_reload = false; } $futures = array(); foreach ($this->getDaemonHandles() as $daemon) { $daemon->update(); if ($daemon->isRunning()) { $futures[] = $daemon->getFuture(); } if ($daemon->isDone()) { $this->removeDaemon($daemon); } } $this->updatePidfile(); $this->updateAutoscale(); if ($futures) { $iter = id(new FutureIterator($futures))->setUpdateInterval(1); foreach ($iter as $future) { break; } } else { if ($this->inGracefulShutdown) { break; } sleep(1); } } exit($this->err); }
public function run() { $this->daemons = array(); foreach ($this->config['daemons'] as $config) { $config += array('argv' => array(), 'autoscale' => array()); $daemon = new PhutilDaemonHandle($this, $config['class'], $this->argv, array('log' => $this->log, 'argv' => $config['argv'], 'load' => $this->libraries, 'autoscale' => $config['autoscale'])); $daemon->setTraceMemory($this->traceMemory); $this->addDaemon($daemon, $config); $group = idx($config['autoscale'], 'group'); if (strlen($group)) { if (isset($this->autoscaleConfig[$group])) { throw new Exception(pht('Two daemons are part of the same autoscale group ("%s"). ' . 'Each daemon autoscale group must be unique.', $group)); } $this->autoscaleConfig[$group] = $config; } } $should_reload = false; while (true) { foreach ($this->modules as $module) { try { if ($module->shouldReloadDaemons()) { $this->logMessage('RELO', pht('Reloading daemons (triggered by overseer module "%s").', get_class($module))); $should_reload = true; } } catch (Exception $ex) { phlog($ex); } } if ($should_reload) { $this->didReceiveReloadSignal(SIGHUP); $should_reload = false; } $futures = array(); foreach ($this->getDaemonHandles() as $daemon) { $daemon->update(); if ($daemon->isRunning()) { $futures[] = $daemon->getFuture(); } if ($daemon->isDone()) { $this->removeDaemon($daemon); } } $this->updatePidfile(); $this->updateAutoscale(); if ($futures) { $iter = id(new FutureIterator($futures))->setUpdateInterval(1); foreach ($iter as $future) { break; } } else { if ($this->inGracefulShutdown) { break; } sleep(1); } } exit($this->err); }
public function run() { $this->daemons = array(); foreach ($this->config['daemons'] as $config) { $config += array('argv' => array(), 'autoscale' => array()); $daemon = new PhutilDaemonHandle($this, $config['class'], $this->argv, array('log' => $this->log, 'argv' => $config['argv'], 'load' => $this->libraries, 'autoscale' => $config['autoscale'])); $daemon->setSilent(!$this->traceMode && !$this->verbose); $daemon->setTraceMemory($this->traceMemory); $this->addDaemon($daemon, $config); } while (true) { $futures = array(); foreach ($this->getDaemonHandles() as $daemon) { $daemon->update(); if ($daemon->isRunning()) { $futures[] = $daemon->getFuture(); } if ($daemon->isDone()) { $this->removeDaemon($daemon); } } $this->updatePidfile(); $this->updateAutoscale(); if ($futures) { $iter = id(new FutureIterator($futures))->setUpdateInterval(1); foreach ($iter as $future) { break; } } else { if ($this->inGracefulShutdown) { break; } sleep(1); } } exit($this->err); }