Exemplo n.º 1
0
 /**
  * @return void
  */
 public function keep()
 {
     Logger::debug(__METHOD__ . '()');
     $this->_stoped = false;
     try {
         while (!$this->_stoped) {
             if (\count($this->_children) < $this->_config->getQuantity()) {
                 $this->_startOne();
                 continue;
             }
             $status = null;
             $pid = \pcntl_wait($status, \WNOHANG);
             if ($pid > 0) {
                 $this->_processExit($pid);
                 continue;
             }
             $this->_checkTimeout();
             \usleep($this->_checkingInterval);
         }
     } catch (StopSignal $ex) {
         Logger::info('Received a StopSignal');
         $this->_waitToEnd();
     }
 }
Exemplo n.º 2
0
 protected function dealWithTermTimeout()
 {
     if ($this->isDealedWithTermTimeout) {
         return false;
     }
     if (microtime(true) - $this->termTime <= $this->config->getTermTimeout()) {
         return false;
     }
     try {
         Logger::info("process[" . $this->getProcess()->getPid() . "] will be killed for termTimeout");
         $this->getProcess()->kill();
         $this->isDealedWithTermTimeout = true;
     } catch (\Exception $e) {
         Logger::err($e);
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * @dataProvider dataProviderOfTermTimeout
  */
 public function testTermTimeout($termTimeout, $expectedIsKillOnTimeout, $expectedTermTimeout)
 {
     $config = new Config(array('termTimeout' => $termTimeout, 'worker' => function () {
     }));
     $this->assertEquals($expectedTermTimeout, $config->getTermTimeout());
     $this->assertEquals($expectedIsKillOnTimeout, $config->isKillingOnTimeoutEnabled());
 }
Exemplo n.º 4
0
 protected function _startOne($groupId, Config $config)
 {
     $target = \call_user_func($config->getFactoryMethod());
     $process = Process::fork($target);
     $this->_children[$process->getPid()] = new ProcessStub($process, $config, $groupId);
 }