From 1b0e255b8f23a1306efc92db96d1a563e94c8866 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Jun 2015 14:26:38 +0200 Subject: [PATCH] Perform background tasks via AJAX request --- .../templates/headIncludeJavaScript.tpl | 10 +++++++ .../BackgroundQueuePerformAction.class.php | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index 580f9c5fc2..c29524d520 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -226,6 +226,16 @@ requirejs.config({ } }); {/if} + + require(['Ajax'], function(Ajax) { + // fire and forget background queue perform task + Ajax.apiOnce({ + url: '{link controller="BackgroundQueuePerform"}{/link}', + ignoreError: true, + silent: true + }); + }); + {if $__sessionKeepAlive|isset} new WCF.System.KeepAlive({@$__sessionKeepAlive}); {/if} diff --git a/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php new file mode 100644 index 0000000000..beffea8a47 --- /dev/null +++ b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php @@ -0,0 +1,26 @@ + + * @package com.woltlab.wcf + * @subpackage action + * @category Community Framework + */ +class BackgroundQueuePerformAction extends AbstractAction { + /** + * @see \wcf\action\IAction::execute() + */ + public function execute() { + parent::execute(); + + @header('HTTP/1.1 204 No Content'); + BackgroundQueueHandler::getInstance()->performNextJob(); + exit; + } +} -- 2.20.1