/** * Runs task */ protected function _run() { $this->_Process = new TaskProcess($this->_task['command'] . $this->_argsToString($this->_task['arguments']), $this->_task['path']); $this->_Process->setTimeout($this->_task['timeout']); try { $this->_Process->start(function ($type, $buffer) { if ('err' === $type) { $this->_Shell->err($buffer); $this->_task['stderr'] .= $buffer; } else { $this->_Shell->out($buffer); $this->_task['stdout'] .= $buffer; } $this->_TaskServer->updated($this->_task); }); while ($this->_Process->isRunning()) { $this->_task['process_id'] = (int) $this->_Process->getPid(); $this->_TaskServer->updateStatistics($this->_task); $this->_Process->checkTimeout(); sleep(Configure::read('Task.checkInterval')); if ($this->_TaskServer->mustStop($this->_task['id'])) { $this->_Process->stop(Configure::read('Task.stopTimeout')); $this->_task['code'] = 143; $this->_task['code_string'] = TaskProcess::$exitCodes[143]; return $this->_stopped(true); } } $this->_task['code'] = $this->_Process->getExitCode(); $this->_task['code_string'] = $this->_Process->getExitCodeText(); } catch (Exception $Exception) { $this->_task['code'] = 134; $this->_task['code_string'] = $Exception->getMessage(); } $this->_stopped(false); }
/** * Tast if task must be stopped * * @param array $task * @param int $taskId * @param bool $mustStop * @dataProvider mustStopProvider */ public function testMustStop(array $task, $taskId, $mustStop) { $this->TaskClient->save($task); $this->assertSame($mustStop, $this->TaskServer->mustStop($taskId)); }