Skip to content

Commit ddfaf70

Browse files
committed
bug symfony#44931 Allow a zero time-limit for messenger:consume (fritzmg)
This PR was merged into the 4.4 branch. Discussion ---------- Allow a zero time-limit for messenger:consume | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - By default `messenger:consume` will run indefinitely and as the docs mention you should monitor the process via Supervisor for example. However on shared hostings this is usually not an option and thus this command will be run via a cronjob there (at least I assume that's the intended best practise in such a case). To ensure the worker exits for each cronjob run, you can use the `--time-limit` option, e.g. ``` bin/console messenger:consume --time-limit=1 ``` However, this would allow the worker to consume multiple message for the duration of 1000ms - so technically if you want the worker to _immediately_ exit each time after it processed the current message queue it should actually be ``` bin/console messenger:consume --time-limit=0 ``` But this does not currently work, as the zero is falsey and thus the `StopWorkerOnTimeLimitListener` will not actually be added. This PR fixes that by checking whether the option was actually supplied or not. Commits ------- 2668c0d allow a zero time-limit
2 parents 7b32f97 + 2668c0d commit ddfaf70

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
173173
$this->eventDispatcher->addSubscriber(new StopWorkerOnMemoryLimitListener($this->convertToBytes($memoryLimit), $this->logger));
174174
}
175175

176-
if ($timeLimit = $input->getOption('time-limit')) {
176+
if (null !== ($timeLimit = $input->getOption('time-limit'))) {
177177
$stopsWhen[] = "been running for {$timeLimit}s";
178178
$this->eventDispatcher->addSubscriber(new StopWorkerOnTimeLimitListener($timeLimit, $this->logger));
179179
}

0 commit comments

Comments
 (0)