-
-
Notifications
You must be signed in to change notification settings - Fork 461
Adding support for DoctrineClearEntityManagerWorkerSubscriber #1043
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
Adding support for DoctrineClearEntityManagerWorkerSubscriber #1043
Conversation
…eset EM in worker (weaverryan) This PR was merged into the 4.4 branch. Discussion ---------- Adding DoctrineClearEntityManagerWorkerSubscriber to reset EM in worker | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes & no :) | New feature? | yes | Deprecations? | no | Tickets | Fix #34073 | License | MIT | Doc PR | symfony/symfony-docs#12575 | DoctrineBundle PR | doctrine/DoctrineBundle#1043 Hi! I've seen a few developers get "bit" by an issue recently: after running `messenger:consume`, the 2nd, 3rd, 4th, etc message that are handled are getting out-of-date data from Doctrine. The reason is simple: A) Consume the 1st message, it queries for `Foo id=1` to do something B) 10 minutes go by C) Consume the 2nd message. It also queries for `Foo id=1`, but because this is already in the identity map, Doctrine re-uses the data that is now *10* minutes old. Even though one worker process handles many messages, the system should (as much as possible) isolate each handler from each other. This is one very practical place we can help people. Also, checking the code, I don't think clearing the entity manager will cause any issues for an EM whose Connection has not been "connected" yet (i.e. it will not cause a connection to be established). We would wire this in DoctrineBundle, and could make it disable-able... in case that's something that's needed. Commits ------- e7b9888 Adding DoctrineClearEntityManagerWorkerSubscriber to reset entity manager in worker
Upstream PR is merged - this should be ready :) |
Thanks @weaverryan! |
It's being a while since this was merged, but, I'm facing the same problem using Doctrine ORM & ODM (mongodb + mariadb schema) in the same project (unrelated). Edit: nvm, I figured out, just had to create a different service, injecting DocumentManager and using just one clear(). Ty |
@weaverryan What's the reason this isn't configurable? My use case here is that I have a simple Instead, I want, persist, persist, persist, persist, flush from my messages... For instance, I might publish 20 messages...
My Stamp might look like this:
I then have my messages, being handled as normal, however, my Listener, will then subscribe to three events.
In full, the class looks like. After writing it, I was batting my head against a wall wondering why the UOW was always empty on next run, and I see it's because the middleware was removed and replaced with an always clearing subscriber. For my use-case, which I feel is legitimate, I have no way of controlling the transaction for flushing. What I wanted, is something like... If idle for 10 seconds, flush. However, don't flush after every message.
|
Hi!
This wires symfony/symfony#34156 as a service. That PR also removes
DoctrineClearEntityManagerMiddleware
, which was never released in DoctrineBundle, so we can safely remove it without any BC worries.The idea (validated if/when #34156 is merged) is that we should run
$entityManager->clear()
between each message that a worker (messenger:consume
) handles. I have not made this configurable - I would rather someone approach us with a valid case for disabling this before doing that. If there is a valid case for wanting this disabled, I don't know what it is - so this would help us learn about such a case.Thanks!