-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] use events consistently in worker #34217
New issu 8000 e
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
|
||
/** | ||
* @param RoutableMessageBus $routableBus | ||
*/ | ||
public function __construct($routableBus, ContainerInterface $receiverLocator, LoggerInterface $logger = null, array $receiverNames = [], /* EventDispatcherInterface */ $eventDispatcher = null) | ||
public function __construct($routableBus, ContainerInterface $receiverLocator, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null, array $receiverNames = []) |
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.
EventDispatcher is required to make the limit options reliable.
a25dffc
to
fe147b6
Compare
87db6f8
to
ffea7d3
Compare
ffea7d3
to
ffbc91e
Compare
src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php
Outdated
Show resolved
Hide resolved
private $logger; | ||
private $memoryResolver; | ||
|
||
public function __construct(int $memoryLimit, LoggerInterface $logger = null, callable $memoryResolver = 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.
wouldn't it make sense to make the logger the third argument?
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.
The memory resolver is mainly for testing and it has been like this before.
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.
Great work 👏
ffbc91e
to
8b767a9
Compare
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.
This is incredible. It's another very nice cleanup with no downside. Big +1 from me after the minor notes.
src/Symfony/Component/Messenger/EventListener/StopWorkerOnSigtermSignalListener.php
Show resolved
Hide resolved
src/Symfony/Component/Messenger/EventListener/StopWorkerOnSigtermSignalListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/EventListener/StopWorkerOnMemoryLimitListener.php
Outdated
Show resolved
Hide resolved
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.
(with minor comments)
8b767a9
to
9911a6d
Compare
9911a6d
to
201f159
Compare
Thank you @Tobion. |
This PR was merged into the 4.4 branch. Discussion ---------- [Messenger] use events consistently in worker | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #32560, #32614, #33843 | License | MIT | Doc PR | The worker had the three ways to handle events 1. $onHandledCallback in `run(array $options = [], callable $onHandledCallback = null)` 2. events dispatched using the event dispatcher 3. hardcoded things inside the worker This PR refactores the messenger worker to only use event dispatching. So instead of a hardcoded `$onHandledCallback` and worker decorators, we use event listeners and we don't need a `WorkerInterface` at all. The behavior of all the options like `--memory-limit` etc remains the same. I introduced two new events - `WorkerStartedEvent` - `WorkerRunningEvent` Together with the existing `WorkerStoppedEvent` it's very symmetrical and solves the referenced issues. Commits ------- 201f159 [Messenger] use events consistently in worker
This PR was merged into the 4.4 branch. Discussion ---------- [Messenger] update events for 4.4 Documentation for symfony/symfony#34217 Commits ------- 3374261 [Messenger] update events for 4.4
The worker had the three ways to handle events
run(array $options = [], callable $onHandledCallback = null)
This PR refactores the messenger worker to only use event dispatching. So instead of a hardcoded
$onHandledCallback
and worker decorators, we use event listeners and we don't need aWorkerInterface
at all. The behavior of all the options like--memory-limit
etc remains the same.I introduced two new events
WorkerStartedEvent
WorkerRunningEvent
Together with the existing
WorkerStoppedEvent
it's very symmetrical and solves the referenced issues.