Allow forcing the check whether a background queue item is due
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:42:38 +0000 (17:42 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:42:38 +0000 (17:42 +0200)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js
wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php

index ba822226a9afedd8808e80de2fccfb34d6d9fab1..47caae7d03f24e7555c86f77f61251fe08f9e8f7 100644 (file)
@@ -103,7 +103,10 @@ requirejs.config({
                });
                
                BootstrapFrontend.setup({
-                       backgroundQueueUrl: '{link controller="BackgroundQueuePerform"}{/link}',
+                       backgroundQueue: {
+                               url: '{link controller="BackgroundQueuePerform"}{/link}',
+                               force: {if $forceBackgroundQueuePerform|isset}true{else}false{/if}
+                       },
                        styleChanger: {if $__wcf->getStyleHandler()->countStyles() > 1}true{else}false{/if}
                });
        });
index c1784db8da3aac058b2541c32589806fb33f28d0..dbf0800397998b93bcd407787fd53ec96c9dbcda 100644 (file)
@@ -37,7 +37,7 @@ define(
                        }
                        
                        this._initUserPopover();
-                       this._invokeBackgroundQueue(options.backgroundQueueUrl);
+                       this._invokeBackgroundQueue(options.backgroundQueue.url, options.backgroundQueue.force);
                },
                
                /**
@@ -66,9 +66,10 @@ define(
                 * Invokes the background queue roughly every 10th request.
                 * 
                 * @param       {string}        url     background queue url
+                * @param       {boolean}       force   whether execution should be forced
                 */
-               _invokeBackgroundQueue: function(url) {
-                       if (Math.random() < 0.1) {
+               _invokeBackgroundQueue: function(url, force) {
+                       if (Math.random() < 0.1 || force) {
                                // 'fire and forget' background queue perform task
                                Ajax.apiOnce({
                                        url: url,
index 548280af79796d073517a1d54885c8b34a91509a..f51efb69b9cf67a2dd1ebbf0b9253e19dac49e5a 100644 (file)
@@ -17,6 +17,16 @@ use wcf\system\WCF;
  * @category   Community Framework
  */
 class BackgroundQueueHandler extends SingletonFactory {
+       /**
+        * Forces checking whether a background queue item is due.
+        * This means that the AJAX request to BackgroundQueuePerformAction is triggered.
+        */
+       public function forceCheck() {
+               WCF::getTPL()->assign([
+                       'forceBackgroundQueuePerform' => true
+               ]);
+       }
+       
        /**
         * Enqueues the given job(s) for execution in the specified number of
         * seconds. Defaults to "as soon as possible" (0 seconds).