Skip to content

Allow a zero time-limit for messenger:consume #44931

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

Merged
merged 1 commit into from
Jan 8, 2022
Merged

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Jan 6, 2022

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.

@micheh
Copy link
Contributor

micheh commented Jan 6, 2022

Why don't you add --limit=1 to stop the worker after one message?

@stof
Copy link
Member

stof commented Jan 6, 2022

@micheh that's a legitimate question. But to me, the PR still makes sense.

@fritzmg
Copy link
Contributor Author

fritzmg commented Jan 6, 2022

Why don't you add --limit=1 to stop the worker after one message?

Using only --limit=1 would still let the worker run indefinitely - until a message actually arrives. I want to let the worker stop immediately.

@OskarStark
Copy link
Contributor

While I am fine with this PR, wouldn't time-limit=1 and limit=1 work for you?

The usage of time-limit=0 could be confusing?

Why not add an option --stop-immediately or sth more explanatory?

@fritzmg
Copy link
Contributor Author

fritzmg commented Jan 8, 2022

The usage of time-limit=0 could be confusing?

Not to an engineer? ;)

@GromNaN GromNaN closed this Jan 8, 2022
@GromNaN GromNaN reopened this Jan 8, 2022
@GromNaN
Copy link
Member

GromNaN commented Jan 8, 2022

Thank you @fritzmg.

@GromNaN GromNaN merged commit ddfaf70 into symfony:4.4 Jan 8, 2022
@fritzmg fritzmg deleted the patch-2 branch March 15, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants