ee6d0dc11c29c2a80a7392f870c55af87a2278c1
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
32 for ( $childId = 0; $childId < $procs; $childId++
) {
34 if ( $pid === -1 ||
$pid === false ) {
35 echo "Error creating child processes\n";
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; }
59 } while ( $deadPid == -1 && !$termReceived );
60 // Kill the remaining children
61 // If they're already dead, say due to SIGTERM, then they'll be zombies until
62 // pcntl_waitpid() below, so the PID won't be reused.
63 foreach ( $children as $childPid ) {
64 if ( $childPid != $deadPid ) {
65 posix_kill( $childPid, SIGTERM
);
68 foreach ( $children as $childPid ) {
69 pcntl_waitpid( $childPid, $status );
76 $wgMemc = wfGetCache( $wgMainCacheType );
79 if ( isset( $options['maxjobs'] ) ) {
80 $maxJobs = $options['maxjobs'];
86 if ( isset( $options['type'] ) )
87 $type = $options['type'];
89 $wgTitle = Title
::newFromText( 'RunJobs.php' );
91 $dbw = wfGetDB( DB_MASTER
);
95 $conds = "job_cmd = " . $dbw->addQuotes($type);
97 while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
100 $job = ($type == false) ?
102 : Job
::pop_type($type);
107 wfWaitForSlaves( 5 );
108 $t = microtime( true );
110 $status = $job->run();
111 $t = microtime( true ) - $t;
112 $timeMs = intval( $t * 1000 );
113 if ( !$job->run() ) {
114 runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
116 runJobsLog( $job->toString() . " t=$timeMs good" );
118 if ( $maxJobs && ++
$n > $maxJobs ) {
125 function runJobsLog( $msg ) {
126 print wfTimestamp( TS_DB
) . " $msg\n";
127 wfDebugLog( 'runJobs', $msg );
130 function handleTermSignal( $signal ) {
131 $GLOBALS['termReceived'] = true;