summaryrefslogtreecommitdiff
path: root/maintenance/runJobs.php
blob: 1340a85770ef11176a6af110148fb52c93d763e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
 * This script starts pending jobs.
 *
 * Usage:
 *  --maxjobs <num> (default 10000)
 *  --type <job_cmd>
 *
 * @file
 * @ingroup Maintenance
 */

$optionsWithArgs = array( 'maxjobs', 'type', 'procs' );
$wgUseNormalUser = true;
require_once( 'commandLine.inc' );

if ( isset( $options['procs'] ) ) {
	$procs = intval( $options['procs'] );
	if ( $procs < 1 || $procs > 1000 ) {
		echo "Invalid argument to --procs\n";
		exit( 1 );
	}
	$fc = new ForkController( $procs );
	if ( $fc->start( $procs ) != 'child' ) {
		exit( 0 );
	}
}

if ( isset( $options['maxjobs'] ) ) {
	$maxJobs = $options['maxjobs'];
} else {
	$maxJobs = 10000;
}

$type = false;
if ( isset( $options['type'] ) )
	$type = $options['type'];

$wgTitle = Title::newFromText( 'RunJobs.php' );

$dbw = wfGetDB( DB_MASTER );
$n = 0;
$conds = '';
if ($type !== false)
	$conds = "job_cmd = " . $dbw->addQuotes($type);

while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
	$offset=0;
	for (;;) {
		$job = ($type == false) ?
				Job::pop($offset)
				: Job::pop_type($type);

		if ($job == false)
			break;

		wfWaitForSlaves( 5 );
		$t = microtime( true );
		$offset=$job->id;
		$status = $job->run();
		$t = microtime( true ) - $t;
		$timeMs = intval( $t * 1000 );
		if ( !$status ) {
			runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
		} else {
			runJobsLog( $job->toString() . " t=$timeMs good" );
		}
		if ( $maxJobs && ++$n > $maxJobs ) {
			break 2;
		}
	}
}


function runJobsLog( $msg ) {
	print wfTimestamp( TS_DB ) . " $msg\n";
	wfDebugLog( 'runJobs', $msg );
}