Add tests for parser tag hooks.
[lhc/web/wiklou.git] / maintenance / gearman / gearmanWorker.php
1 <?php
2
3 $optionsWithArgs = array( 'fake-job', 'procs' );
4 require( dirname( __FILE__ ) . '/../commandLine.inc' );
5 require( dirname( __FILE__ ) . '/gearman.inc' );
6
7 ini_set( 'memory_limit', '150M' );
8
9 if ( isset( $options['procs'] ) ) {
10 $procs = $options['procs'];
11 if ( $procs < 1 || $procs > 1000 ) {
12 echo "Invalid number of processes, please specify a number between 1 and 1000\n";
13 exit( 1 );
14 }
15 $fc = new ForkController( $procs, ForkController::RESTART_ON_ERROR );
16 if ( $fc->start() != 'child' ) {
17 exit( 0 );
18 }
19 }
20
21 if ( !$args ) {
22 $args = array( 'localhost' );
23 }
24
25 if ( isset( $options['fake-job'] ) ) {
26 $params = unserialize( $options['fake-job'] );
27 MWGearmanJob::runNoSwitch( $params );
28 }
29
30 $worker = new NonScaryGearmanWorker( $args );
31 $worker->addAbility( 'mw_job' );
32 $worker->beginWork( 'wfGearmanMonitor' );
33
34 function wfGearmanMonitor( $idle, $lastJob ) {
35 static $lastSleep = 0;
36 $interval = 5;
37 $now = time();
38 if ( $now - $lastSleep >= $interval ) {
39 wfWaitForSlaves( $interval );
40 $lastSleep = $now;
41 }
42 return false;
43 }