Perform background tasks via AJAX request
authorTim Düsterhus <duesterhus@woltlab.com>
Sun, 21 Jun 2015 12:26:38 +0000 (14:26 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 21 Jun 2015 12:59:26 +0000 (14:59 +0200)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php [new file with mode: 0644]

index 580f9c5fc22556f0b60b1d4c6029f8c214e4b5c6..c29524d5209889c879cc4934711f347b7c52cc5c 100644 (file)
@@ -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 (file)
index 0000000..beffea8
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+namespace wcf\action;
+use wcf\system\background\BackgroundQueueHandler;
+
+/**
+ * Performs background queue jobs.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+       }
+}