-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Messenger] Custom method argument $onHandledCallback for worker with command messenger:consume #32560
Comments
IMHO, the Symfony should be reset after each message. I do that in my custom worker and I Opened an issue in swarrot to do the same. The status of the message should not be taken in consideration. |
@weaverryan one idea would be to dispatch an event to replace the callback, WDYT? |
Why would you miss them? They would get sent with the next batch of messages, wouldn't they? |
@Tobion You're right, but they would be sent with unrelated logs records like:
|
trying to address that issue #32614 |
If you sent messages in batches there are always messages in one batch that might not belong together. But what is the problem you have? Logs are time based not group based. |
I would like to send all logs that are related to the same HTTP request or handled message in one batch. For instance I am using this monolog config. The problem I have is that I cannot achieve this behavior right now with messenger worker while it's perfectly fine with HTTP request. Another solution that works would be to reset the kernel after each message the worker handled. monolog:
handlers:
sentry_buffer:
type: fingers_crossed
action_level: warning
handler: buffer
channels: ["!event", "!security"]
buffer:
type: buffer
handler: sentry
sentry:
type: service
id: 'sentry_handler' |
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
Description
At the moment it does not look possible to have a custom
$onHandledCallback
on theWorker
used bymessenger:consume
command.See ->
symfony/src/Symfony/Component/Messenger/Worker.php
Line 93 in 52e9fb9
My use case is that I would like to
reset
monolog buffered handler at this very moment to send my error logs in batch to Sentry.I thought about using
WorkerMessageFailedEvent
but then I would miss important logging messages such as :symfony/src/Symfony/Component/Messenger/Worker.php
Line 145 in 52e9fb9
symfony/src/Symfony/Component/Messenger/Worker.php
Line 159 in 52e9fb9
Possible solution
Perhaps by replacing the callable with an interface that could be autowired in the command, not sure.
The text was updated successfully, but these errors were encountered: