Geo: Introduce an EventsManager factory to handle replication events creation
Every event that is replicated is persisted on the database with a class that loosely follows this pattern: Geo::#{What}#{Action}Event like this example: Geo::RepositoryCreatedEvent. The initialization is handled by another class with similar name pattern: Geo::RepositoryCreatedEventStore. So for every “action” on every “thing” that we replicate there is at least 2 new classes just to register the events.
In order to organize the codebase and make it easier to expand what we replicate, easiser to test etc, we should try to simplify this.
My proposal is that we implement a central factory that will handle events creation and can also be used for other purposes. The API will be something like this:
Geo::EventManager.publish_event(:repository, :created, model)
This allows us to do a few things in a easier way than current strucuture:
- Intercept the events to do all sorts of things like logging, making it easier to test, etc
- Allow us to test with other replication mechanisms like plugging a rabbitmq/nats
- Publish to a PubSub (Redis/Rails Channel) for debug purpose (like showing live whats going on via a websocket livestream component, would be useful for debugging)
- Easier to understand what we replicate and what we are lacking
With this structure in place, we can improve our testing by having something like:
expect { Something.action }.to register_geo_replication_event(:repository, :created)
and/or implement something similar to the Sidekiq::Testing.fake! that will register the events in memory so you can easily/cheaply inspect them etc.