-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Could not persist aggregate because it seems to be changed by another process after it was retrieved in the current process. Current in-memory version is 1 #325
Comments
Repo, if required: https://github.com/JustSteveKing/phponline.dev-new |
Here's a whole discussion on concurrency: #214 There are two ways to solve your problem: use the command bus with the retry middleware (mentioned in that discussion), or manually refresh the ARs on places where these errors arise. PS: please reopen this issue if the linked discussion doesn't solve the problem! |
@brendt is this part in the v7 documentation at all? It sounds like it would solve the issue - but wouldn't mind reading your recommended approach 😄 |
I don't think it is… I added it as a kind of experimental feature, but maybe it's time to add it to the docs now. Have you tried it out? |
Not yet @brendt - if it is in the laravel event sourcing couese I could probably figure it out though |
@JustSteveKing I'm wondering if you've been able to follow the discussion on #214 and resolved it. I haven't been able to follow through and implement the suggestions but we have worked out a way to make concurrent persists work for us in the mean time. Solution seems hacky and thus haven't bothered to create a PR to this package to have it added. Found ourselves in a situation where you need the aggregate to persist no matter what. When dealing with transactions (payments), after processing all validation rules and ensuring this is a valid request that needs to be processed by an external microservice, it is bad to throw an error such as Find below the link to a sample repository created, (on a separate branch), to enable concurrent persists. I am really hoping it helps someone and or someone improves upon it in a way that would also help us very much. https://github.com/anabeto93/spatie-es-auto-discovery/pull/new/feature/allow-concurrent-persists Helper function here is When stress testing the current implementation of the gateway with event-sourcing using |
Hey @anabeto93 I haven't tried this recently if I am honest, however I am about to start another event sourcing project soon - so will be able to see where this is in terms of ability to achieve. I had issues following the discussion if I am honest, as the docs did not have anything about actually using the command bus. I will dig into this and see what I can figure out |
My first time using v7 of the package, and had some issues with aggregates last night.
Could not persist aggregate PostAggregate (uuid: 19dad81e-b6ab-4012-a04a-401e1d35747d) because it seems to be changed by another process after it was retrieved in the current process. Current in-memory version is 1
Using Laravel 9.2.0
PHP 8.1
Aggregate:
Event:
Service Provider:
Projector:
The event is persisted in the database during testing with no errors, but when I interact with my code from the web UI - I get this issue. The aggregate is being triggered by a Livewire component that uses a service class to trigger the aggregate:
Livewire Component:
Service class:
As you can see the service class tries to persist the aggregate, and this is where it fails. In my test code all I am doing is making sure that the event is stored:
The text was updated successfully, but these errors were encountered: