public function Processor::processQueue in Advanced Queue 8
Processes the given queue.
Jobs will be claimed and processed one by one until the configured processing time ($queue->getProcessingTime()) passes.
Parameters
\Drupal\advancedqueue\Entity\QueueInterface $queue: The queue.
Return value
int The number of processed jobs.
Overrides ProcessorInterface::processQueue
File
- src/
Processor.php, line 58
Class
- Processor
- Provides the default queue processor.
Namespace
Drupal\advancedqueueCode
public function processQueue(QueueInterface $queue) {
// Start from a clean slate.
$queue
->getBackend()
->cleanupQueue();
// Allow unlimited processing time only on the CLI.
$processing_time = $queue
->getProcessingTime();
if ($processing_time == 0 && PHP_SAPI != 'cli') {
$processing_time = 90;
}
$expected_end = $this->time
->getCurrentTime() + $processing_time;
$num_processed = 0;
while (TRUE) {
$job = $queue
->getBackend()
->claimJob();
if (!$job) {
// The queue is empty. Stop here.
break;
}
$this
->processJob($job, $queue);
$num_processed++;
if ($processing_time && $this->time
->getCurrentTime() >= $expected_end) {
// Time limit reached. Stop here.
break;
}
}
return $num_processed;
}