Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Classes/Command/CrontabCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,29 @@ public function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<info>Executing scheduled tasks…</info>');
$defaultWorkerTimeout = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerTimeout'] ?? 0;
$defaultWorkerForks = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerForks'] ?? 1;
$idleSleep = (int)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['idleSleep'] ?? 5);
$taskRepository = GeneralUtility::makeInstance(TaskRepository::class);
$crontab = GeneralUtility::makeInstance(Crontab::class, $taskRepository);
$processManager = GeneralUtility::makeInstance(ProcessManager::class, (int)($input->getOption('forks') ?? $defaultWorkerForks));
$crontab->prepareSchedulingFinishedTasks($processManager);

$runUntil = time() + (int)($input->getOption('timeout') ?? $defaultWorkerTimeout);
do {
$tasksFound = false;
foreach ($crontab->dueTasks() as $taskIdentifier) {
$processManager->add(
TaskProcess::createFromTaskDefinition($taskRepository->findByIdentifier($taskIdentifier))
);
$tasksFound = true;
}

// Monitor processes to finish and wait for free spot
$processManager->wait();

// If no tasks were found, sleep a bit longer to reduce CPU usage
if (!$tasksFound) {
sleep($idleSleep);
}
} while (time() < $runUntil);
$processManager->finish();
$lock->release();
Expand Down
2 changes: 2 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ hideSchedulerModule = 1
workerTimeout = 0
# cat=basic//; type=integer; label=Default number of due tasks allowed to be run in parallel.
workerForks = 1
# cat=basic//; type=integer; label=Seconds to sleep when idle to preserve CPU (when last query did not return any tasks to execute)
idleSleep = 5