$job->flagRunning(); include 'plugins/' . $job->pluginName . '/task_' . $job->page . '_loader.php'; } } } // List all job to do in the queue folder foreach (glob(get_ini('UPLOAD_FOLDER') . "queue/*.xml") as $jobName) { $fileFullPath = str_replace('\\', '/', $jobName); $jobName = substr($jobName, strrpos($jobName, '/') + 1, strlen($jobName) - strrpos($jobName, '/') - 1); // Valid the xml file with XSD $domXmlFile = new DOMDocument(); $domXmlFile->preserveWhiteSpace = false; $domXmlFile->Load(get_ini('UPLOAD_FOLDER') . 'queue/' . $jobName); if ($domXmlFile->schemaValidate('plugins/core/xsd/core.xsd')) { if ($procM->getId($jobName) == 0) { $childProcId = $procM->create(0, $jobName, '', 10); usleep(500); if ($procM->getCount($jobName) > 1) { // Wait some millisecond to avoid concurent write usleep(mt_rand(100, 20000)); if ($procM->getCount($jobName) > 1) { $procM->delete($childProcId); exit(0); } } echo _('#core#_#18#') . ' ' . $jobName . '.<BR>'; $proc = new processus($childProcId); $procM->update($proc->id, 'running', '2'); if (file_exists(get_ini('UPLOAD_FOLDER') . 'running/' . $jobName)) { unlink(get_ini('UPLOAD_FOLDER') . 'running/' . $jobName); }
echo date('Y-m-d H:i:s') . ' - The parameter MAX_PROCESS is to low.' . "\n"; exit(20); } // Stop runner process if there is some which are not updated $q0 = get_link()->prepare('UPDATE ' . get_ini('BDD_PREFIX') . 'core_processus SET status=:status, deleted_date=:deleted_date, deleted_id=:deleted_id WHERE cmd=:cmd AND edited_date<:min_date AND deleted_date = 0'); $q0->execute(array('status' => 'failed', 'cmd' => get_ini('PROCESS_NAME'), 'min_date' => time() - 120, 'deleted_id' => $_SESSION['USER_ID'], 'deleted_date' => time())); // Check if other runner already exist $q0 = get_link()->prepare("SELECT id AS ID FROM " . get_ini('BDD_PREFIX') . "core_processus WHERE cmd = :cmd AND (deleted_date = 0 AND timeout>:current_date)"); $q0->execute(array('cmd' => get_ini('PROCESS_NAME'), 'current_date' => time())); $r0 = $q0->fetch(PDO::FETCH_OBJ); if (isset($r0->ID)) { echo date('Y-m-d H:i:s') . ' - There is already a loaded runner.' . "\n"; exit(0); } else { $procM = new processusManager(); $procId = $procM->create(0, get_ini('PROCESS_NAME'), '', time() + get_ini('PROCESS_LIFE_TIME')); $proc = new processus($procId); echo date('Y-m-d H:i:s') . ' - Runner loaded - process id: ' . $proc->id . "\n"; $lastCollectorTime = 0; while ($endTime > time()) { // Check if another process don't kill this process $q0 = get_link()->prepare("SELECT status AS PROCESSSTATUS FROM " . get_ini('BDD_PREFIX') . "core_processus WHERE id = :id AND status = 'failed'"); $q0->execute(array('id' => $proc->id)); $r0 = $q0->fetch(PDO::FETCH_OBJ); if (isset($r0->PROCESSSTATUS)) { echo date('Y-m-d H:i:s') . ' - Another process kill me.' . "\n"; exit(0); } // Update process status $procM->update($proc->id, 'running', floor((time() - $beginTime) * 100 / ($endTime - $beginTime))); // Collector task / Limit run to avoid to much I/O