/** * @param int $taskIndex * @param string $logDir * @param string $phpPath * @param string $tasksetPath * @param KSchedularTaskConfig $taskConfig */ public function __construct($taskIndex, $logDir, $phpPath, $tasksetPath, KSchedularTaskConfig $taskConfig) { $taskConfig->setTaskIndex($taskIndex); $logName = str_replace('kasync', '', strtolower($taskConfig->name)); $logDate = date('Y-m-d'); $logFile = "{$logDir}/{$logName}-{$taskIndex}-{$logDate}.log"; $sysLogFile = "{$taskConfig->name}.{$taskIndex}"; $this->taskConfig = $taskConfig; $taskConfigStr = base64_encode(serialize($taskConfig)); $cmdLine = ''; $cmdLine .= is_null($taskConfig->affinity) ? '' : "{$tasksetPath} -c " . ($taskConfig->affinity + $taskIndex) . ' '; $cmdLine = "{$phpPath} "; $cmdLine .= "{$taskConfig->scriptPath} "; $cmdLine .= "{$taskConfigStr} "; $cmdLine .= "'[" . mt_rand() . "]' "; if ($taskConfig->getUseSyslog()) { $cmdLine .= "2>&1 | logger -t {$sysLogFile}"; } else { $cmdLine .= ">> {$logFile} 2>&1"; } $descriptorspec = array(); // stdin is a pipe that the child will read from // $descriptorspec = array(0 => array("pipe", "r")); // stdin is a pipe that the child will read from // 1 => array ( "file" ,$logFile , "a" ) , // 2 => array ( "file" ,$logFile , "a" ) , // 1 => array("pipe", "w"), // stdout is a pipe that the child will write to // 2 => array("pipe", "w"), // stdout is a pipe that the child will write to // 2 => array("file", "{$work_dir}/error-output.txt", "a") // stderr is a file to write to $other_options = array('suppress_errors' => FALSE, 'bypass_shell' => FALSE); KalturaLog::debug("Now executing [{$cmdLine}], [{$other_options}]"); $process = proc_open($cmdLine, $descriptorspec, $pipes, null, null, $other_options); $this->pipes = $pipes; $this->handle = $process; $this->dieTime = time() + $taskConfig->maximumExecutionTime + 5; }
/** * @param KSchedularTaskConfig $taskConfig */ private function exeJob(KSchedularTaskConfig $taskConfig) { $this->debug(__LINE__, "exeJob({$taskConfig->name})"); $taskConfig->setTaskIndex(1); //$taskConfig->setInitOnly(true); $instance = new $taskConfig->type($taskConfig); $instance->run(); $instance->done(); }
public function __construct(KSchedularTaskConfig $taskConfig, $taskIndex) { $taskConfig->setTaskIndex($taskIndex); $this->taskConfig = $taskConfig; $this->dieTime = time() + $taskConfig->maximumExecutionTime + 5; }