* @since 3.0
*/
class BackgroundQueuePerformAction extends AbstractAction {
+ /**
+ * number of jobs that will be processed per invocation
+ * @var integer
+ */
+ public static $jobsPerRun = 5;
+
/**
* @inheritDoc
*/
parent::execute();
header('Content-type: application/json');
- BackgroundQueueHandler::getInstance()->performNextJob();
+ for ($i = 0; $i < self::$jobsPerRun; $i++) {
+ if (BackgroundQueueHandler::getInstance()->performNextJob() === false) {
+ // there were no more jobs
+ break;
+ }
+ }
echo BackgroundQueueHandler::getInstance()->getRunnableCount();
exit;
}
/**
* Performs the (single) job that is due next.
* This method automatically handles requeuing in case of failure.
+ *
+ * @return boolean true if this call attempted to execute a job regardless of its result
*/
public function performNextJob() {
WCF::getDB()->beginTransaction();
$row = $statement->fetchSingleRow();
if (!$row) {
// nothing to do here
- return;
+ return false;
}
// lock job
// somebody stole the job
// this cannot happen unless MySQL violates it's contract to lock the row
// -> silently ignore, there will be plenty of other opportunities to perform a job
- return;
+ return true;
}
WCF::getDB()->commitTransaction();
$committed = true;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$row['jobID']]);
}
+
+ return true;
}
/**