Inheritance: extends TaskModel
コード例 #1
0
ファイル: TaskServer.php プロジェクト: qieangel2013/zys
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new TaskServer();
     }
     return self::$instance;
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * Test virtual fields
  * 
  * @param array $task
  * @param array $fieldValues
  * @dataProvider virtualFieldsProvider
  */
 public function testVirtualFields(array $task, array $fieldValues)
 {
     $this->TaskServer->deleteAll(array(1 => 1));
     foreach ($task as $field => &$value) {
         if (!in_array($field, array('stderr'), true)) {
             $value = (new DateTime($value))->format('Y-m-d H:i:s');
         }
     }
     $this->TaskServer->save($task);
     $taskData = $this->TaskServer->read();
     foreach ($fieldValues as $field => $value) {
         $this->assertEquals($value, (int) $taskData[$this->TaskServer->alias][$field], $field, (int) ($value / 10));
     }
 }