3 * This script starts pending jobs.
6 * --maxjobs <num> (default 10000)
10 * @ingroup Maintenance
13 $optionsWithArgs = array( 'maxjobs', 'type', 'procs' );
14 $wgUseNormalUser = true;
15 require_once( 'commandLine.inc' );
17 if ( isset( $options['procs'] ) ) {
18 $procs = intval( $options['procs'] );
19 if ( $procs < 1 ||
$procs > 1000 ) {
20 echo "Invalid argument to --procs\n";
24 // Don't share DB or memcached connections
30 // Create the child processes
32 for ( $childId = 0; $childId < $procs; $childId++
) {
34 if ( $pid === -1 ||
$pid === false ) {
35 echo "Error creating child processes\n";
42 $children[$pid] = true;
47 pcntl_signal( SIGTERM
, 'handleTermSignal', false );
48 // Wait for a child to exit
50 $termReceived = false;
52 $deadPid = pcntl_wait( $status );
53 // Run signal handlers
54 if ( function_exists( 'pcntl_signal_dispatch' ) ) {
55 pcntl_signal_dispatch();
57 declare (ticks
=1) { $status = $status; }
60 unset( $children[$deadPid] );
62 // Respond to TERM signal
63 if ( $termReceived ) {
64 foreach ( $children as $childPid => $unused ) {
65 posix_kill( $childPid, SIGTERM
);
67 $termReceived = false;
69 } while ( count( $children ) );
75 $wgMemc = wfGetCache( $wgMainCacheType );
78 if ( isset( $options['maxjobs'] ) ) {
79 $maxJobs = $options['maxjobs'];
85 if ( isset( $options['type'] ) )
86 $type = $options['type'];
88 $wgTitle = Title
::newFromText( 'RunJobs.php' );
90 $dbw = wfGetDB( DB_MASTER
);
94 $conds = "job_cmd = " . $dbw->addQuotes($type);
96 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
99 $job = ($type == false) ?
101 : Job
::pop_type($type);
106 wfWaitForSlaves( 5 );
107 $t = microtime( true );
109 $status = $job->run();
110 $t = microtime( true ) - $t;
111 $timeMs = intval( $t * 1000 );
112 if ( !$job->run() ) {
113 runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
115 runJobsLog( $job->toString() . " t=$timeMs good" );
117 if ( $maxJobs && ++
$n > $maxJobs ) {
124 function runJobsLog( $msg ) {
125 print wfTimestamp( TS_DB
) . " $msg\n";
126 wfDebugLog( 'runJobs', $msg );
129 function handleTermSignal( $signal ) {
130 $GLOBALS['termReceived'] = true;