* Refactored the forking code from runJobs.php to a new class called ForkController...
[lhc/web/wiklou.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', 'procs' );
14 $wgUseNormalUser = true;
15 require_once( 'commandLine.inc' );
16
17 if ( isset( $options['procs'] ) ) {
18 $procs = intval( $options['procs'] );
19 if ( $procs < 1 || $procs > 1000 ) {
20 echo "Invalid argument to --procs\n";
21 exit( 1 );
22 }
23 $fc = new ForkController;
24 if ( $fc->forkWorkers( $procs ) == 'parent' ) {
25 $fc->runParent();
26 exit( 0 );
27 }
28 }
29
30 if ( isset( $options['maxjobs'] ) ) {
31 $maxJobs = $options['maxjobs'];
32 } else {
33 $maxJobs = 10000;
34 }
35
36 $type = false;
37 if ( isset( $options['type'] ) )
38 $type = $options['type'];
39
40 $wgTitle = Title::newFromText( 'RunJobs.php' );
41
42 $dbw = wfGetDB( DB_MASTER );
43 $n = 0;
44 $conds = '';
45 if ($type !== false)
46 $conds = "job_cmd = " . $dbw->addQuotes($type);
47
48 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
49 $offset=0;
50 for (;;) {
51 $job = ($type == false) ?
52 Job::pop($offset)
53 : Job::pop_type($type);
54
55 if ($job == false)
56 break;
57
58 wfWaitForSlaves( 5 );
59 $t = microtime( true );
60 $offset=$job->id;
61 $status = $job->run();
62 $t = microtime( true ) - $t;
63 $timeMs = intval( $t * 1000 );
64 if ( !$job->run() ) {
65 runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
66 } else {
67 runJobsLog( $job->toString() . " t=$timeMs good" );
68 }
69 if ( $maxJobs && ++$n > $maxJobs ) {
70 break 2;
71 }
72 }
73 }
74
75
76 function runJobsLog( $msg ) {
77 print wfTimestamp( TS_DB ) . " $msg\n";
78 wfDebugLog( 'runJobs', $msg );
79 }
80
81