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

Implementing a Process Manager #72

Closed
GuiguiMtl opened this issue Mar 26, 2018 · 3 comments
Closed

Implementing a Process Manager #72

GuiguiMtl opened this issue Mar 26, 2018 · 3 comments

Comments

@GuiguiMtl
Copy link

On a previous Issue I asked of the difference between Process Manager and Session and ended up creating a process manager.
One of the issue I am facing is that as a result several Aggregate are being tracked in the Session. When I commit for the first time the tracked aggregates are not cleared therefore still tracked. That's probably because
So during the second commit, it tries to save the aggregate previously save again but this create a Concurrency Issue because the version of the aggregate descriptor is not updated.

One solution I have found it to update the commit with this
await Task.WhenAll(_trackedAggregates.Values.Where(aggregate => aggregate.Aggregate.GetUncommittedChanges().Any()).Select(x => _repository.Save(x.Aggregate, x.Version, cancellationToken)));

In order to only save Aggregates that does not have any other changes to save.

The other option would be to not wait for the save of aggregate to be finished to actually clear the tracked aggregates of the session but I can't figure a way to make that work.

Does that make sense or am I going to break something I do not realize yet ?

@gautema
Copy link
Owner

gautema commented Mar 26, 2018 via email

@GuiguiMtl
Copy link
Author

Thanks for your answer.

The session is not cleared because after committing the first aggregate, the event is broadcasted to the system. It is handle by the event handler which creates and save the process manager. At this point the session keeps track of the aggregates that was saved previously and the process manager.

That's because even if it is asynchronous everything is done in this given order :
->Commit
-> Flush changes to aggregate
-> Save event to EventStore
-> Publish Events
-> Event Handler Handles Event
-> Launch Process Manager
-> Commit changes made on the process manager
-> Concurrency exception because we are still in the save of the first commit. As we did not reach the clear aggregates statement of the first Commit, we try to save a version of an Aggregate which is the previous version.

Creating a new session in the handler would probably fix the issue but I feel like it would break the idea of Session you were trying to bring with it, no ?

@gautema
Copy link
Owner

gautema commented Apr 23, 2018

Sorry the late reply. I don't think you should use the same session. Hopefully you have fixed this by now.

@gautema gautema closed this as completed Apr 23, 2018
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

2 participants