]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/runJobs.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / maintenance / runJobs.php
1 <?php
2 /**
3  * This script starts pending jobs.
4  *
5  * Usage:
6  *  --maxjobs <num> (default 10000)
7  *  --type <job_cmd>
8  *
9  * @file
10  * @ingroup Maintenance
11  */
12
13 $optionsWithArgs = array( 'maxjobs', 'type' );
14 $wgUseNormalUser = true;
15 require_once( 'commandLine.inc' );
16 require_once( "$IP/includes/JobQueue.php" );
17 require_once( "$IP/includes/FakeTitle.php" );
18
19 if ( isset( $options['maxjobs'] ) ) {
20         $maxJobs = $options['maxjobs'];
21 } else {
22         $maxJobs = 10000;
23 }
24
25 $type = false;
26 if ( isset( $options['type'] ) )
27         $type = $options['type'];
28
29 $wgTitle = Title::newFromText( 'RunJobs.php' );
30
31 $dbw = wfGetDB( DB_MASTER );
32 $n = 0;
33 $conds = '';
34 if ($type !== false)
35         $conds = "job_cmd = " . $dbw->addQuotes($type);
36
37 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
38         $offset=0;
39         for (;;) {
40                 $job = ($type == false) ?
41                                 Job::pop($offset)
42                                 : Job::pop_type($type);
43
44                 if ($job == false)
45                         break;
46
47                 wfWaitForSlaves( 5 );
48                 print wfTimestamp( TS_DB ) . "  " . $job->id . "  " . $job->toString() . "\n";
49                 $offset=$job->id;
50                 if ( !$job->run() ) {
51                         print wfTimestamp( TS_DB ) . "  Error: {$job->error}\n";
52                 }
53                 if ( $maxJobs && ++$n > $maxJobs ) {
54                         break 2;
55                 }
56         }
57 }
58