Drain queue faster by processing up to five items, if items are due
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 9 Feb 2016 20:16:32 +0000 (21:16 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 9 Feb 2016 20:16:32 +0000 (21:16 +0100)
wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js
wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php

index dbf0800397998b93bcd407787fd53ec96c9dbcda..5749a71500efaa5b8463f1b201eab7d04e5ec623 100644 (file)
@@ -18,6 +18,8 @@ define(
 {
        "use strict";
        
+       var queueInvocations = 0;
+       
        /**
         * @exports     WoltLab/WCF/BootstrapFrontend
         */
@@ -69,12 +71,20 @@ define(
                 * @param       {boolean}       force   whether execution should be forced
                 */
                _invokeBackgroundQueue: function(url, force) {
+                       var again = this._invokeBackgroundQueue.bind(this, url, true);
+                       
                        if (Math.random() < 0.1 || force) {
                                // 'fire and forget' background queue perform task
                                Ajax.apiOnce({
                                        url: url,
                                        ignoreError: true,
-                                       silent: true
+                                       silent: true,
+                                       success: (function(data) {
+                                               queueInvocations++;
+                                               
+                                               // process up to 5 queue items per page load
+                                               if (data > 0 && queueInvocations < 5) setTimeout(again, 1000);
+                                       }).bind(this)
                                });
                        }
                }
index a91b7e1e4254ed05f4a5e9e48bd8e9c1a3f5b406..f2a1a8fb2cb33b88ad889c9337c6149e19b6b158 100644 (file)
@@ -20,8 +20,9 @@ class BackgroundQueuePerformAction extends AbstractAction {
        public function execute() {
                parent::execute();
                
-               @header('HTTP/1.1 204 No Content');
+               header('Content-type: application/json');
                BackgroundQueueHandler::getInstance()->performNextJob();
+               echo BackgroundQueueHandler::getInstance()->getRunnableCount();
                exit;
        }
 }