-
Hello, In our app we have two types of users, a partner which has all rights and a collaborator. Whenever a partner does an event, it is validated directly but if a collaborator does an event, it is in pending state. Pending events can be canceled by partners to remove their effect on the database. Let's take A as a validated event and B as a pending one. Both are inside my aggregate stream like this: [A,B]. But now, I run my mutation to cancel event B. After the cancellation, my stream would look like this: [A] which is what I want. But then when I fire an event C, my stream gets messed up and looks like this: [C, A, C]. This is a problem because I have events that depend on others. For example this A event would give 50 points to toto, but C would transfer these 50 points to tata. So the next time the stream will be replayed on an Aggregate, I would have 'Score with id: A.id not found'. So my problem is with canceling events. What I mean by that is to cancel every change on my database that has been made by the read side of the 'canceled' events. To do so, I remove everything from the database, unlink events I want to cancel ( by deleting the stream and linking again on the same stream name only events I want to keep) and replay all events but canceled ones. Then, I start a rebuild from a stream with RailsEventStore::Projection. But somehow after i add a new event to my aggregate, in duplicates it in the stream even though my aggregate looks fine. I put pry inside the gem files to find out where it is happening and it seems to happen in append_to_stream_serialized_events. The input for me looks fine but somehow the storage of events into stream fails by adding the new event twice (once at the beginning of the stream and another time at the end). To illustrate more clearly: with the same example as before, in my aggregate I only have 1 in @events_applied before append_to_stream and my stream looks like this: [A]. After the append_to_stream method, my stream looks like this: [C,A,C] and the aggregate can't be inspected because of the dependence error mentioned before. I also tried to emit points to tata instead of transferring points as event C , and then, my stream still looks like [C, A, C] after the append_to_stream method but in my aggregate i do have 3 events applied but only the score object of tata, not toto. My code in mutation: https://ghostbin.com/ZNh5b Hope you can help me out, i'm available for further questions. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @Tyflomate
Why you want to remove events from stream? Maybe I do not understand your use case but it looks for me that cancellation of pending event by a partner is just another business action and this should be represented by another domain event. Then all side effects should depend on the handling of this cancellation event. I would prefer to see what had happened with the pending event (why it's side effects are not in read models anymore) and storing a cancellation domain event will be a perfect way for me to reason about the system state. Have you considered cancellation domain event instead of relinking the streams?
Having 2 C events in the same stream looks strange for me. Are this the same event or 2 events of type C? |
Beta Was this translation helpful? Give feedback.
-
Well it is an option but it would be inconvenient. We do not have only emit points as a cancelable event and we chose rails event store especially for this feature: to be able to replay events in prospection of this cancelation feature, we actually thought about your solution but it is a plan B because it will require much more time and some events are tricky to revert.
I also saw this week that we are way behind in term of version (we are still on 1.1 and 2.3 is released) so i'll upgrade this and come to you with a repo asap ! |
Beta Was this translation helpful? Give feedback.
Well it is an option but it would be inconvenient. We do not have only emit points as a cancelable event and we chose rails event store especially for this feature: to be able to replay events in prospection of this cancelation feature, we actually thought about your solution but it is a plan B because it will require much more time and some events are tricky to revert.