From bb091b00c4ba7467d6789b979c5192478f7e9aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Wed, 19 Nov 2025 10:57:39 +0100 Subject: [PATCH 1/2] [FEATURE] Idle sleep - when last query did not return task to execute --- Classes/Command/CrontabCommand.php | 9 +++++++++ ext_conf_template.txt | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Classes/Command/CrontabCommand.php b/Classes/Command/CrontabCommand.php index f828343..9df9233 100644 --- a/Classes/Command/CrontabCommand.php +++ b/Classes/Command/CrontabCommand.php @@ -56,6 +56,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Executing scheduled tasks…'); $defaultWorkerTimeout = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerTimeout'] ?? 0; $defaultWorkerForks = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerForks'] ?? 1; + $idleSleep = $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)); @@ -63,13 +64,21 @@ public function execute(InputInterface $input, OutputInterface $output): int $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(); diff --git a/ext_conf_template.txt b/ext_conf_template.txt index f20741b..3f869f4 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -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 From a2a65609cc32db540848ec3339df840293f4b338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20N=C3=B8rgaard=20F=C3=A6rch?= Date: Mon, 24 Nov 2025 11:53:37 +0100 Subject: [PATCH 2/2] [BUGFIX] idleSleep from extension setting is not integer --- Classes/Command/CrontabCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Command/CrontabCommand.php b/Classes/Command/CrontabCommand.php index 9df9233..10de96f 100644 --- a/Classes/Command/CrontabCommand.php +++ b/Classes/Command/CrontabCommand.php @@ -56,7 +56,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Executing scheduled tasks…'); $defaultWorkerTimeout = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerTimeout'] ?? 0; $defaultWorkerForks = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['workerForks'] ?? 1; - $idleSleep = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['crontab']['idleSleep'] ?? 5; + $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));