/** * Work on a queue and execute jobs. * * @param string $queueName the name of the queue * @param integer $timeout time a queue waits for a job in seconds * @param integer $limit number of jobs to be done, -1 for all jobs in queue, 0 for work infinite * @return void */ public function work($queueName, $timeout = 0, $limit = 1) { $this->getLogger()->info(sprintf('Work on queue "%s" with a timeout of "%s" and a limit of "%d" in process "%s"', $queueName, $timeout, $limit, getmypid())); $memoryLimit = (int) $this->extensionConfiguration->get('memoryLimit'); $lastRestart = $this->registry->get(Registry::DAEMON_KILL_KEY); if ($limit === self::LIMIT_INFINITE) { $timeout = max(1, $timeout); } do { if ($this->shouldRun()) { $continueWork = $this->waitAndExecute($queueName, $timeout); if ($limit === self::LIMIT_QUEUE && $continueWork === false) { break; } else { if ($limit > 0 && --$limit < 1) { break; } } } if ($this->memoryExceeded($memoryLimit) || $this->shouldRestart($lastRestart)) { $this->getLogger()->info(sprintf('Stopped work on queue "%s" in process "%s"', $queueName, getmypid())); break; } } while (true); }
/** * @param string $queueName * @return QueueInterface * @throws JobQueueException */ public function getQueue($queueName) { if (!isset($this->queues[$queueName])) { $settings = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['jobqueue']; $className = $this->extensionConfiguration->get('defaultQueue'); $options = []; if (isset($settings[$queueName])) { $className = isset($settings[$queueName]['className']) ? $settings[$queueName]['className'] : null; $options = isset($settings[$queueName]['options']) ? (array) $settings[$queueName]['options'] : []; } if (empty($options)) { $options = isset($settings[$className]['options']) ? (array) $settings[$className]['options'] : []; } if (!isset($options['timeout'])) { $defaultTimeout = (int) $this->extensionConfiguration->get('defaultTimeout'); $options['timeout'] = $defaultTimeout > 0 ? $defaultTimeout : null; } if (empty($className)) { throw new JobQueueException('No jobqueue class name configuration found.', 1448488276); } $classNameParts = ClassNamingUtility::explode($className); ExtensionManagementUtility::isLoaded(GeneralUtility::camelCaseToLowerCaseUnderscored($classNameParts['extensionName']), true); $queue = $this->objectManager->get($className, $queueName, $options); if (!$queue instanceof QueueInterface) { throw new JobQueueException("Queue '{$queueName}' is not a queue.", 1446318455); } $this->queues[$queueName] = $queue; } return $this->queues[$queueName]; }
/** * @return void */ public function initializeObject() { $this->maxAttemps = (int) $this->extensionConfiguration->get('maxAttemps'); }