summaryrefslogtreecommitdiff
path: root/maintenance/gearman/gearmanWorker.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2009-06-10 13:00:47 +0200
committerPierre Schmitz <pierre@archlinux.de>2009-06-10 13:00:47 +0200
commit72e90545454c0e014318fa3c81658e035aac58c1 (patch)
tree9212e3f46868989c4d57ae9a5c8a1a80e4dc0702 /maintenance/gearman/gearmanWorker.php
parent565a0ccc371ec1a2a0e9b39487cbac18e6f60e25 (diff)
applying patch to version 1.15.0
Diffstat (limited to 'maintenance/gearman/gearmanWorker.php')
-rw-r--r--maintenance/gearman/gearmanWorker.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/maintenance/gearman/gearmanWorker.php b/maintenance/gearman/gearmanWorker.php
new file mode 100644
index 00000000..0b26ff9f
--- /dev/null
+++ b/maintenance/gearman/gearmanWorker.php
@@ -0,0 +1,41 @@
+<?php
+
+$optionsWithArgs = array( 'fake-job', 'procs' );
+require( dirname(__FILE__).'/../commandLine.inc' );
+require( dirname(__FILE__).'/gearman.inc' );
+
+if ( isset( $options['procs'] ) ) {
+ $procs = $options['procs'];
+ if ( $procs < 1 || $procs > 1000 ) {
+ echo "Invalid number of processes, please specify a number between 1 and 1000\n";
+ exit( 1 );
+ }
+ $fc = new ForkController( $procs, ForkController::RESTART_ON_ERROR );
+ if ( $fc->start() != 'child' ) {
+ exit( 0 );
+ }
+}
+
+if ( !$args ) {
+ $args = array( 'localhost' );
+}
+
+if ( isset( $options['fake-job'] ) ) {
+ $params = unserialize( $options['fake-job'] );
+ MWGearmanJob::runNoSwitch( $params );
+}
+
+$worker = new NonScaryGearmanWorker( $args );
+$worker->addAbility( 'mw_job' );
+$worker->beginWork( 'wfGearmanMonitor' );
+
+function wfGearmanMonitor( $idle, $lastJob ) {
+ static $lastSleep = 0;
+ $interval = 5;
+ $now = time();
+ if ( $now - $lastSleep >= $interval ) {
+ wfWaitForSlaves( $interval );
+ $lastSleep = $now;
+ }
+ return false;
+}