/** * * @throws \Comos\Qpm\Process\Exception * @return boolean */ public function dealWithTimeout() { if (!$this->isTimeout()) { return false; } if ($this->isDealedWithTimeout) { if (!$this->config->isKillOnTimeout()) { $this->dealWithTermTimeout(); } return false; } $this->isDealedWithTimeout = true; Logger::info("process[" . $this->getProcess()->getPid() . "] will be terminated for timeout"); $this->invokeOnTimeout(); try { if ($this->config->isKillOnTimeout()) { $this->getProcess()->kill(); } else { $this->termTime = microtime(true); $this->getProcess()->terminate(); } } catch (\Exception $e) { Logger::err($e); return false; } return true; }
/** * @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->isKillOnTimeout()); }