[Messenger] New messenger:stop-workers Command#30754
Conversation
| <tag name="cache.pool" /> | ||
| </service> | ||
|
|
||
| <service id="cache.messenger" parent="cache.app" public="false"> |
There was a problem hiding this comment.
I'm using cache.app because we need this value to be shared amongst multiple servers and it should persist through deploys. However, there is no precedent that I know if for the core to use cache.app. And also, perhaps the service id should be more specific to the "messenger restart" - and not just cache.messenger?
There was a problem hiding this comment.
Can't we use a bus instead here to broadcast to all workers?
There was a problem hiding this comment.
If we keep a cache pool, it should be a dedicated one btw, extending from cache.app.
There was a problem hiding this comment.
Can't we use a bus instead here to broadcast to all workers?
It means we'd have to build a broadcast feature, which we don't have nor plan (yet?) to have.
There was a problem hiding this comment.
I've made the cache service id more specific - still extends from cache.app like before
c0fc67e to
6ea1002
Compare
|
Recently |
|
#30708 has been merged now, so this one can be rebased. |
6ea1002 to
be03f89
Compare
|
I've kept the longer command name here, because you won't type it often (it's a command to run at deploy mostly) and I think the longer name makes it a bit more descriptive. This is ready for review! It does actually work locally ;) |
be03f89 to
5897162
Compare
|
Thank you @weaverryan. |
…ryan) This PR was squashed before being merged into the 4.3-dev branch (closes #30754). Discussion ---------- [Messenger] New messenger:stop-workers Command | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | Kinda of #29451 | License | MIT | Doc PR | symfony/symfony-docs#11236 o/ me again. This requires and is built on top of #30708 When you deploy, all workers need to be stopped and restarted. That's not currently possible, unless you manually track the pids and send a SIGTERM signal. We can make that much easier :). Now run: ``` bin/console messenger:stop-workers ``` And it will signal to all workers (even if they're distributed on other servers) that they should stop, once they finish processing their current message. This is done via a key in `cache.app`. Cheers! Commits ------- 5897162 [Messenger] New messenger:stop-workers Command
| <tag name="cache.pool" /> | ||
| </service> | ||
|
|
||
| <service id="cache.messenger.restart_workers_signal" parent="cache.app" public="false"> |
There was a problem hiding this comment.
public=false should be removed
| $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); | ||
|
|
||
| $cacheItem = $this->restartSignalCachePool->getItem(StopWhenRestartSignalIsReceived::RESTART_REQUESTED_TIMESTAMP_KEY); | ||
| $cacheItem->set(time()); |
There was a problem hiding this comment.
I'd suggest using microtime(true) everywhere
| $this->decoratedWorker->stop(); | ||
| } | ||
|
|
||
| private function shouldRestart(int $workerStartedAt) |
This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] fix review | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Fixes my review left in #30754 /cc @weaverryan FYI Commits ------- a3de902 [Messenger] fix review
| <argument type="collection" /> <!-- Receiver names --> | ||
| <argument type="service" id="messenger.retry_strategy_locator" /> | ||
| <argument type="service" id="event_dispatcher" /> | ||
| <call method="setCachePoolForRestartSignal"> |
There was a problem hiding this comment.
Why is this one a call while it's an argument on the other one? 🤔
…(sroze) This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] Add `psr/cache` on Messenger's dependencies | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30754 | License | MIT | Doc PR | ø Commits ------- 0b5004f Add `psr/cache` on Messenger's dependencies
o/ me again.
This requires and is built on top of #30708
When you deploy, all workers need to be stopped and restarted. That's not currently possible, unless you manually track the pids and send a SIGTERM signal. We can make that much easier :).
Now run:
And it will signal to all workers (even if they're distributed on other servers) that they should stop, once they finish processing their current message. This is done via a key in
cache.app.Cheers!