Merge "Allow adding Deleted log entries"
[lhc/web/wiklou.git] / maintenance / runJobs.php
index b488fe9..9b86e1b 100644 (file)
@@ -176,9 +176,12 @@ class RunJobs extends Maintenance {
        private function getBackoffTimeToWait( Job $job ) {
                global $wgJobBackoffThrottling;
 
-               if ( !isset( $wgJobBackoffThrottling[$job->getType()] ) ) {
+               if ( !isset( $wgJobBackoffThrottling[$job->getType()] ) ||
+                       $job instanceof DuplicateJob // no work was done
+               ) {
                        return 0; // not throttled
                }
+
                $itemsPerSecond = $wgJobBackoffThrottling[$job->getType()];
                if ( $itemsPerSecond <= 0 ) {
                        return 0; // not throttled
@@ -186,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;