Allow floating point values for $wgJobBackoffThrottling
authorGergo Tisza <gtisza@wikimedia.org>
Wed, 7 May 2014 21:12:34 +0000 (21:12 +0000)
committerGergo Tisza <gtisza@wikimedia.org>
Fri, 9 May 2014 00:40:21 +0000 (00:40 +0000)
Useful for jobs which take longer than a second to finish.

Change-Id: I2e57d61fd67b97fbd593274b31e1bfada8f522f5

includes/DefaultSettings.php
maintenance/runJobs.php

index c281893..3ed71d1 100644 (file)
@@ -6176,6 +6176,7 @@ $wgJobTypesExcludedFromDefaultQueue = array( 'AssembleUploadChunks', 'PublishSta
  * may have a variable number of work items, as is the case with batch jobs.
  * This is used by runJobs.php and not jobs run via $wgJobRunRate.
  * These settings should be global to all wikis.
+ * @var float[]
  */
 $wgJobBackoffThrottling = array();
 
index f69a3a3..9b86e1b 100644 (file)
@@ -189,9 +189,11 @@ class RunJobs extends Maintenance {
 
                $seconds = 0;
                if ( $job->workItemCount() > 0 ) {
-                       $seconds = floor( $job->workItemCount() / $itemsPerSecond );
-                       $remainder = $job->workItemCount() % $itemsPerSecond;
-                       $seconds += ( mt_rand( 1, $itemsPerSecond ) <= $remainder ) ? 1 : 0;
+                       $exactSeconds = $job->workItemCount() / $itemsPerSecond;
+                       // use randomized rounding
+                       $seconds = floor( $exactSeconds );
+                       $remainder = $exactSeconds - $seconds;
+                       $seconds += ( mt_rand() / mt_getrandmax() < $remainder ) ? 1 : 0;
                }
 
                return (int)$seconds;