-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathBackgroundQueuePerformAction.class.php
More file actions
46 lines (38 loc) · 1.27 KB
/
BackgroundQueuePerformAction.class.php
File metadata and controls
46 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace wcf\action;
use Laminas\Diactoros\Response\JsonResponse;
use wcf\system\background\BackgroundQueueHandler;
use wcf\system\WCF;
/**
* Performs background queue jobs.
*
* @author Tim Duesterhus
* @copyright 2001-2023 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
final class BackgroundQueuePerformAction extends AbstractAction
{
/**
* number of jobs that will be processed per invocation
*/
public static int $jobsPerRun = 10;
#[\Override]
public function execute(): JsonResponse
{
parent::execute();
for ($i = 0; $i < self::$jobsPerRun; $i++) {
// Reset the memory usage for each background job, allowing to measure each individual
// background job's memory usage without a memory-heavy job skewing the numbers for
// the following jobs.
\memory_reset_peak_usage();
if (BackgroundQueueHandler::getInstance()->performNextJob() === false) {
// there were no more jobs
break;
}
}
WCF::getSession()->deleteIfNew();
return new JsonResponse(
BackgroundQueueHandler::getInstance()->getRunnableCount()
);
}
}