From 27f8a1487cc6739dc73cf2a62c876e0e11016ec0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 24 Jul 2015 17:42:38 +0200 Subject: [PATCH] Allow forcing the check whether a background queue item is due --- com.woltlab.wcf/templates/headIncludeJavaScript.tpl | 5 ++++- .../install/files/js/WoltLab/WCF/BootstrapFrontend.js | 7 ++++--- .../system/background/BackgroundQueueHandler.class.php | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index ba822226a9..47caae7d03 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -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} }); }); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js b/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js index c1784db8da..dbf0800397 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js @@ -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, diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index 548280af79..f51efb69b9 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -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). -- 2.20.1