public function execute() { global $wgTitle; if ( $this->hasOption( 'procs' ) ) { $procs = intval( $this->getOption( 'procs' ) ); if ( $procs < 1 || $procs > 1000 ) { $this->error( "Invalid argument to --procs", true ); } $fc = new ForkController( $procs ); if ( $fc->start() != 'child' ) { exit( 0 ); } } $maxJobs = $this->getOption( 'maxjobs', false ); $maxTime = $this->getOption( 'maxtime', false ); $startTime = time(); $type = $this->getOption( 'type', false ); $wgTitle = Title::newFromText( 'RunJobs.php' ); $dbw = wfGetDB( DB_MASTER ); $n = 0; $conds = ''; if ( $type !== false ) { $conds = "job_cmd = " . $dbw->addQuotes( $type ); } while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) { $offset = 0; for ( ; ; ) { $job = !$type ? Job::pop( $offset ) : Job::pop_type( $type ); if ( !$job ) { break; } wfWaitForSlaves( 5 ); $t = microtime( true ); $offset = $job->id; $status = $job->run(); $t = microtime( true ) - $t; $timeMs = intval( $t * 1000 ); if ( !$status ) { $this->runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" ); } else { $this->runJobsLog( $job->toString() . " t=$timeMs good" ); } if ( $maxJobs && ++$n > $maxJobs ) { break 2; } if ( $maxTime && time() - $startTime > $maxTime ) { break 2; } } } }
public function execute() { global $wgTitle; if ($this->hasOption('procs')) { $procs = intval($this->getOption('procs')); if ($procs < 1 || $procs > 1000) { $this->error("Invalid argument to --procs", true); } $fc = new ForkController($procs); if ($fc->start() != 'child') { exit(0); } } $maxJobs = $this->getOption('maxjobs', false); $maxTime = $this->getOption('maxtime', false); $startTime = time(); $type = $this->getOption('type', false); $wgTitle = Title::newFromText('RunJobs.php'); $dbw = wfGetDB(DB_MASTER); $n = 0; $conds = ''; if ($type !== false) { $conds = "job_cmd = " . $dbw->addQuotes($type); } while ($dbw->selectField('job', 'job_id', $conds, 'runJobs.php')) { $offset = 0; for (;;) { $job = !$type ? Job::pop($offset) : Job::pop_type($type); if (!$job) { break; } //check for similar (but not IDENTICAL (different timestamp allowed) jobs and delete them. $dbw->delete('job', array('job_cmd' => $job->command, 'job_title' => $job->title->getDBkey()), __METHOD__); wfWaitForSlaves(); $t = microtime(true); $offset = $job->id; $status = $job->run(); $t = microtime(true) - $t; $timeMs = intval($t * 1000); if (!$status) { $this->runJobsLog($job->toString() . " t={$timeMs} error={$job->error}"); } else { $this->runJobsLog($job->toString() . " t={$timeMs} good"); } if ($maxJobs && ++$n > $maxJobs) { break 2; } if ($maxTime && time() - $startTime > $maxTime) { break 2; } } } }
/** * Main entry point, tak job from queue and run it * * @access public */ public function execute() { global $wgUser, $wgApiRunJobsPerRequest; ini_set("memory_limit", -1); ini_set("max_execution_time", 0); $result = array(); $done = 0; # # check if wiki is not readonly # if (!wfReadOnly()) { $params = $this->extractRequestParams(); if (!$wgUser->isAllowed("runjob")) { $this->dieUsageMsg(array("cantrunjobs")); } # # api param has precedence # if (isset($params["max"])) { $max = $params["max"]; if (is_numeric($max) && $max > 0 && $max <= 100) { $this->maxJobs = $max; } } elseif (!empty($wgApiRunJobsPerRequest) && is_numeric($wgApiRunJobsPerRequest) && $wgApiRunJobsPerRequest > 0 && $wgApiRunJobsPerRequest <= 100) { $this->maxJobs = $wgApiRunJobsPerRequest; } foreach (range(1, $this->maxJobs) as $counter) { if (isset($params["type"])) { $job = Job::pop_type($params["type"]); } else { // refreshlinks2 has precedence $job = Job::pop_type("refreshLinks2"); if (!$job) { // any job $job = Job::pop(); } } if ($job) { $status = $job->run(); $result["job"][] = array("id" => $job->id, "type" => $job->command, "status" => $job->toString(), "error" => $job->error); $done++; } else { // there's no job in queue, finish loop, release request break; } } } $this->wikiaLog(array("type" => isset($params["type"]) ? $params["type"] : "undefined", "maxJobs" => $this->maxJobs, "done" => $done)); $result["left"] = $this->checkQueue($done); $this->getResult()->addValue(null, $this->getModuleName(), $result); $result = array(); }
$maxJobs = 10000; } $type = false; if (isset($options['type'])) { $type = $options['type']; } $wgTitle = Title::newFromText('RunJobs.php'); $dbw = wfGetDB(DB_MASTER); $n = 0; $conds = ''; if ($type !== false) { $conds = "job_cmd = " . $dbw->addQuotes($type); } while ($dbw->selectField('job', 'job_id', $conds, 'runJobs.php')) { $offset = 0; for (;;) { $job = $type == false ? Job::pop($offset) : Job::pop_type($type); if ($job == false) { break; } wfWaitForSlaves(5); print wfTimestamp(TS_DB) . " " . $job->id . " " . $job->toString() . "\n"; $offset = $job->id; if (!$job->run()) { print wfTimestamp(TS_DB) . " Error: {$job->error}\n"; } if ($maxJobs && ++$n > $maxJobs) { break 2; } } }
function runTranscodeJobs(){ $dbw = wfGetDB( DB_MASTER ); $type = 'webVideoTranscode'; // Set the condition to only run the webVideoTranscode $conds = "job_cmd = " . $dbw->addQuotes( $type ); while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) { $offset = 0; for ( ; ; ) { $job = Job::pop_type( $type ); if ( !$job ) break; wfWaitForSlaves( 5 ); $t = microtime( true ); $offset = $job->id; $status = $job->run(); $t = microtime( true ) - $t; $timeMs = intval( $t * 1000 ); } } }