Better logging in runJobs.php. Committing for test on server.
[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' );
14 $wgUseNormalUser = true;
15 require_once( 'commandLine.inc' );
16
17 if ( isset( $options['maxjobs'] ) ) {
18 $maxJobs = $options['maxjobs'];
19 } else {
20 $maxJobs = 10000;
21 }
22
23 $type = false;
24 if ( isset( $options['type'] ) )
25 $type = $options['type'];
26
27 $wgTitle = Title::newFromText( 'RunJobs.php' );
28
29 $dbw = wfGetDB( DB_MASTER );
30 $n = 0;
31 $conds = '';
32 if ($type !== false)
33 $conds = "job_cmd = " . $dbw->addQuotes($type);
34
35 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
36 $offset=0;
37 for (;;) {
38 $job = ($type == false) ?
39 Job::pop($offset)
40 : Job::pop_type($type);
41
42 if ($job == false)
43 break;
44
45 wfWaitForSlaves( 5 );
46 $t = microtime( true );
47 $offset=$job->id;
48 $status = $job->run();
49 $t = microtime( true ) - $t;
50 $timeMs = intval( $t * 1000 );
51 if ( !$job->run() ) {
52 runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
53 } else {
54 runJobsLog( $job->toString() . " t=$timeMs good" );
55 }
56 if ( $maxJobs && ++$n > $maxJobs ) {
57 break 2;
58 }
59 }
60 }
61
62
63 function runJobsLog( $msg ) {
64 print wfTimestamp( TS_DB ) . " $msg\n";
65 wfDebugLog( 'runJobs', $msg );
66 }
67