/** * 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); }
protected function compileWithCommand($bin, $source, $target) { $sourceFilePath = trim(Director::getAbsFile($source)); $targetFilePath = trim(Director::getAbsFile($target)); $command = $bin . " " . escapeshellarg($sourceFilePath); $process = new \Symfony\Component\Process\Process($command); $process->run(); if ($process->isSuccessful()) { $css = $process->getOutput(); if (!file_exists(dirname($targetFilePath))) { mkdir(dirname($targetFilePath), null, true); } file_put_contents($targetFilePath, $css); $this->filesCacheAdd($source); $this->log[] = ["compiled {$source} to {$target}", 'info']; } else { $message = $process->getErrorOutput(); if ($process->getExitCode() != 1 || !$message) { $message = "\"{$command}\": non-zero exit code {$process->getExitCode()} '{$process->getExitCodeText()}'. (Output: '{$message}')"; } $this->log[] = ["failed to compile {$source} with {$bin}: {$message}", 'error']; SS_Log::log(new Exception($message), SS_Log::ERR); } }