Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] add event for all handled messages even failing one #32614

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

Closed
wants to merge 1 commit into from

Conversation

B-Galati
Copy link
Contributor

@B-Galati B-Galati commented Jul 19, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? no
Fixed tickets #32560
License MIT
Doc PR TODO symfony/symfony-docs#

fix #32560 by dispatching WorkerMessageHandledEvent on every handled messages instead of successful ones.

I rename the current WorkerMessageHandledEvent to WorkerMessageHandledSuccessfullyEvent to make things more explicit and keep that extension point.

@B-Galati B-Galati requested a review from sroze as a code owner July 19, 2019 05:43
@B-Galati B-Galati changed the title [messenger] add event for all handled messages even failing one [Messenger] add event for all handled messages even failing one Jul 19, 2019
@nicolas-grekas nicolas-grekas added this to the next milestone Jul 19, 2019
Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, but I'm not sure we need two events. The new placement of WorkerMessageHandledEvent might be enough, except that we could now pass a boolean flag to it to indicate whether or not the message was handled successfully (and add some wasHandledSuccessfuly() method to the object).

@B-Galati
Copy link
Contributor Author

@weaverryan So we would have both WorkerMessageFailedEvent and WorkerMessageHandledEvent and the second one would have a method wasHandledSuccessfuly if I understand.

The thing I am concerned about is how can we properly document that the envelop carried by each of this event is different while the event itself could give the same information: successful or not .

Perhaps it adds unnecessary complexity for the end user? One would ask himself if he should subscribe to WorkerMessageFailedEvent or WorkerMessageHandledEvent to know when an event failed.
While the current solution is quite straighforward (I am biased).

Would love to have other opinions :-)

@B-Galati
Copy link
Contributor Author

Friendly ping @weaverryan

1 similar comment
@B-Galati
Copy link
Contributor Author

Friendly ping @weaverryan

@weaverryan
Copy link
Member

No, I meant that we would only have one event WorkerMessageHandledEvent - but in the new location where you’ve placed it. There would be no other event. But then on that event, we would pass whether or not the message was successful to that event class so that the user can use it to determine if the message was successfully handled or not.

Or, we have two events - but one explicitly only for failed messages (WorkerMessageHandlingFailedEvent) and another explicitly only for successful messages (WorkerMessageHandlesSuccessfullyEvent).

As I understand it now, with this PR, we have 2 events, but one is called always and the other only on success. Why not just 1 event for both cases or 2 events that are mutually exclusive?

Sorry for the delay!

@B-Galati
Copy link
Contributor Author

B-Galati commented Oct 23, 2019

Makes sense to have 1 event like proprosed. I will update the PR soonish.

Thanks 👍

@B-Galati
Copy link
Contributor Author

In fact, I am not sure when I will have the time to work on this.

@Tobion
Copy link
Contributor

Tobion commented Nov 1, 2019

Closing in favor of #34217

@Tobion Tobion closed this Nov 1, 2019
nicolas-grekas added a commit that referenced this pull request Nov 5, 2019
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
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
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.

[Messenger] Custom method argument $onHandledCallback for worker with command messenger:consume
6 participants