Merge "Allow and use type Language instead of string for $lang of doEditSectionLink"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / ThumbnailRenderJob.php
index 49eabbb..63575eb 100644 (file)
@@ -103,8 +103,10 @@ class ThumbnailRenderJob extends Job {
 
                wfDebug( __METHOD__ . ": hitting url {$thumbUrl}\n" );
 
+               // T203135 We don't wait for the request to complete, as this is mostly fire & forget.
+               // Looking at the HTTP status of requests that take less than 1s is a sanity check.
                $request = MWHttpRequest::factory( $thumbUrl,
-                       [ 'method' => 'HEAD', 'followRedirects' => true ],
+                       [ 'method' => 'HEAD', 'followRedirects' => true, 'timeout' => 1 ],
                        __METHOD__
                );
 
@@ -122,10 +124,26 @@ class ThumbnailRenderJob extends Job {
                        return true;
                } elseif ( $statusCode ) {
                        $this->setLastError( __METHOD__ . ": incorrect HTTP status $statusCode when hitting $thumbUrl" );
+               } elseif ( $status->hasMessage( 'http-timed-out' ) ) {
+                       // T203135 we ignore timeouts, as it would be inefficient for this job to wait for
+                       // minutes for the slower thumbnails to complete.
+                       return true;
                } else {
                        $this->setLastError( __METHOD__ . ': HTTP request failure: '
                                . Status::wrap( $status )->getWikiText( null, null, 'en' ) );
                }
                return false;
        }
+
+       /**
+        * Whether to retry the job.
+        * @return bool
+        */
+       public function allowRetries() {
+               // ThumbnailRenderJob is a warmup for the thumbnails cache,
+               // so loosing it is not a problem. Most times the job fails
+               // for non-renderable or missing images which will not be fixed
+               // by a retry, but will create additional load on the renderer.
+               return false;
+       }
 }