Follow-up to r51279
[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 if ( isset( $options['procs'] ) ) {
8 $procs = $options['procs'];
9 if ( $procs < 1 || $procs > 1000 ) {
10 echo "Invalid number of processes, please specify a number between 1 and 1000\n";
11 exit( 1 );
12 }
13 $fc = new ForkController( $procs, ForkController::RESTART_ON_ERROR );
14 if ( $fc->start() != 'child' ) {
15 exit( 0 );
16 }
17 }
18
19 if ( !$args ) {
20 $args = array( 'localhost' );
21 }
22
23 if ( isset( $options['fake-job'] ) ) {
24 $params = unserialize( $options['fake-job'] );
25 MWGearmanJob::runNoSwitch( $params );
26 }
27
28 $worker = new NonScaryGearmanWorker( $args );
29 $worker->addAbility( 'mw_job' );
30 $worker->beginWork( 'wfGearmanMonitor' );
31
32 function wfGearmanMonitor( $idle, $lastJob ) {
33 static $lastSleep = 0;
34 $interval = 5;
35 $now = time();
36 if ( $now - $lastSleep >= $interval ) {
37 wfWaitForSlaves( $interval );
38 $lastSleep = $now;
39 }
40 return false;
41 }