-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Add a new time limit receiver #27130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
private $timeLimit; | ||
private $logger; | ||
|
||
public function __construct(ReceiverInterface $decoratedReceiver, int $timeLimit, LoggerInterface $logger = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please name the variable like $timeLimitInSeconds to make it clear what unit this is in
if ($endTime < time()) { | ||
$this->stop(); | ||
if (null !== $this->logger) { | ||
$this->logger->info('Receiver stopped due to time limit of {timeLimit} reached', array('timeLimit' => $this->timeLimit)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit seconds missing
|
||
$timeoutReceiver = new StopWhenTimeLimitIsReachedReceiver($decoratedReceiver, 1, $logger); | ||
$timeoutReceiver->receive(function () { | ||
sleep(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in order to not really wait for 2s during tests, the test case should be @group time-sensitive
@@ -70,6 +72,10 @@ protected function configure(): void | |||
Use the --memory-limit option to stop the worker if it exceeds a given memory usage limit. You can use shorthand byte values [K, M or G]: | |||
|
|||
<info>php %command.full_name% <receiver-name> --memory-limit=128M</info> | |||
|
|||
Use the --time-limit option to stop the worker if it the given time limit is reached: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- if it
+ when
- given time limit
+ given time limit (in seconds)
@sdelicata your commits have multiple authors: could you squash them into one for us please? |
@sroze Done ! |
Thank you @sdelicata. |
This PR was merged into the 4.1-dev branch. Discussion ---------- [Messenger] Add a new time limit receiver | Q | A | ------------- | --- | Branch? | master for features | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes | License | MIT New feature to add a time limit option to the ConsumeMessagesCommand. ``` bin/console messenger:consume-messages <receiver-name> -t 3600 ``` Commits ------- 5536ee1 Add a new time limit receiver
if ($endTime < time()) { | ||
$this->stop(); | ||
if (null !== $this->logger) { | ||
$this->logger->info('Receiver stopped due to time limit of {timeLimit}s reached', array('timeLimit' => $this->timeLimitInSeconds)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use short array syntax
New feature to add a time limit option to the ConsumeMessagesCommand.