3 * This script starts pending jobs.
6 * --maxjobs <num> (default 10000)
10 * @ingroup Maintenance
13 require_once( "Maintenance.php" );
15 class RunJobs
extends Maintenance
{
16 public function __construct() {
17 global $wgUseNormalUser;
18 parent
::__construct();
19 $this->mDescription
= "Run pending jobs";
20 $this->addParam( 'maxjobs', 'Maximum number of jobs to run', false, true );
21 $this->addParam( 'type', 'Type of job to run', false, true );
22 $this->addParam( 'procs', 'Number of processes to use', false, true );
23 $wgUseNormalUser = true;
26 public function execute() {
28 if ( $this->hasOption( 'procs' ) ) {
29 $procs = intval( $this->getOption('procs') );
30 if ( $procs < 1 ||
$procs > 1000 ) {
31 $this->error( "Invalid argument to --procs\n", true );
33 $fc = new ForkController( $procs );
34 if ( $fc->start( $procs ) != 'child' ) {
38 $maxJobs = $this->getOption( 'maxjobs', 10000 );
39 $type = $this->getOption( 'type', false );
40 $wgTitle = Title
::newFromText( 'RunJobs.php' );
41 $dbw = wfGetDB( DB_MASTER
);
45 $conds = "job_cmd = " . $dbw->addQuotes($type);
47 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
50 $job = ($type == false) ?
52 : Job
::pop_type($type);
58 $t = microtime( true );
60 $status = $job->run();
61 $t = microtime( true ) - $t;
62 $timeMs = intval( $t * 1000 );
64 $this->runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
66 $this->runJobsLog( $job->toString() . " t=$timeMs good" );
68 if ( $maxJobs && ++
$n > $maxJobs ) {
77 * @param $msg String The message to log
79 private function runJobsLog( $msg ) {
80 $this->output( wfTimestamp( TS_DB
) . " $msg\n" );
81 wfDebugLog( 'runJobs', $msg );
85 $maintClass = "RunJobs";
86 require_once( DO_MAINTENANCE
);