00001 <?php 00013 $optionsWithArgs = array( 'maxjobs', 'type', 'procs' ); 00014 $wgUseNormalUser = true; 00015 require_once( 'commandLine.inc' ); 00016 00017 if ( isset( $options['procs'] ) ) { 00018 $procs = intval( $options['procs'] ); 00019 if ( $procs < 1 || $procs > 1000 ) { 00020 echo "Invalid argument to --procs\n"; 00021 exit( 1 ); 00022 } 00023 $fc = new ForkController( $procs ); 00024 if ( $fc->start( $procs ) != 'child' ) { 00025 exit( 0 ); 00026 } 00027 } 00028 00029 if ( isset( $options['maxjobs'] ) ) { 00030 $maxJobs = $options['maxjobs']; 00031 } else { 00032 $maxJobs = 10000; 00033 } 00034 00035 $type = false; 00036 if ( isset( $options['type'] ) ) 00037 $type = $options['type']; 00038 00039 $wgTitle = Title::newFromText( 'RunJobs.php' ); 00040 00041 $dbw = wfGetDB( DB_MASTER ); 00042 $n = 0; 00043 $conds = ''; 00044 if ($type !== false) 00045 $conds = "job_cmd = " . $dbw->addQuotes($type); 00046 00047 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) { 00048 $offset=0; 00049 for (;;) { 00050 $job = ($type == false) ? 00051 Job::pop($offset) 00052 : Job::pop_type($type); 00053 00054 if ($job == false) 00055 break; 00056 00057 wfWaitForSlaves( 5 ); 00058 $t = microtime( true ); 00059 $offset=$job->id; 00060 $status = $job->run(); 00061 $t = microtime( true ) - $t; 00062 $timeMs = intval( $t * 1000 ); 00063 if ( !$status ) { 00064 runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" ); 00065 } else { 00066 runJobsLog( $job->toString() . " t=$timeMs good" ); 00067 } 00068 if ( $maxJobs && ++$n > $maxJobs ) { 00069 break 2; 00070 } 00071 } 00072 } 00073 00074 00075 function runJobsLog( $msg ) { 00076 print wfTimestamp( TS_DB ) . " $msg\n"; 00077 wfDebugLog( 'runJobs', $msg ); 00078 } 00079 00080