Skip to content
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

Lower the priority of event listeners #135

Open
priyadi opened this issue Feb 13, 2025 · 0 comments
Open

Lower the priority of event listeners #135

priyadi opened this issue Feb 13, 2025 · 0 comments

Comments

@priyadi
Copy link
Contributor

priyadi commented Feb 13, 2025

Currently HandleMonitorStampListener has the same priority as DoctrineClearEntityManagerWorkerSubscriber

bin/console debug:event-dispatcher WorkerMessageHandledEvent

Registered Listeners for "Symfony\Component\Messenger\Event\WorkerMessageHandledEvent" Event
============================================================================================

 ------- -------------------------------------------------------------------------------------------------------- ---------- 
  Order   Callable                                                                                                 Priority  
 ------- -------------------------------------------------------------------------------------------------------- ---------- 
  #1      Zenstruck\Messenger\Monitor\EventListener\HandleMonitorStampListener::handleSuccess()                    0         
  #2      Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber::onWorkerMessageHandled()   0         
 ------- -------------------------------------------------------------------------------------------------------- ---------- 

In my installation above, HandleMonitorStampListener will be executed first.

The problem is that if there are unflushed entities, messenger-monitor-bundle will inadvertently flush them. On the other hand, without messenger-monitor-bundle, DoctrineClearEntityManagerWorkerSubscriber will clear these pending entities, and they won't be flushed. So we are getting different behaviors depending on whether messenger-monitor-bundle is installed or not.

I propose lowering the priority of HandleMonitorStampListener to something like -100, so that DoctrineClearEntityManagerWorkerSubscriber always runs earlier to clear the unflushed entities.

Also, ORMStorage should also call clear() after flush().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant