inaka / sumo_db

Erlang Persistency Framework
http://inaka.github.io/sumo_db/
Apache License 2.0
174 stars 37 forks source link

Fix sumo to support that one event manager to handle multiple docs and vice versa #280

Closed cabol closed 8 years ago

cabol commented 8 years ago

Currently sumo has a big limitation, events are attached to the docs, they keep a one-to-one relationship, which means, there is only one event to one doc. Therefore, it is not possible:

Both scenarios are pretty common, so the idea is fix sumo to support this feature.

One alternative to the config might be, instead of associate one doc to one manager like this:

{events, [
  {my_doc_1, my_event_manager}
]}

Change the config to allow to define a manager with a filter, that might be a list with the docs that we want to get events:

{events, [
  {my_event_manager. [my_doc_1, my_doc_2]},
  % If we want to listen all events from all docs, just let the list empty
  {other_event_manager, []}
]}
elbrujohalcon commented 8 years ago

I would prefer this for "listen to all events":

{events, [{my_super_manager, all}]}
cabol commented 8 years ago

@elbrujohalcon agreed. On other hand, I think the scenario "One event manager to handle events from different docs" might be cover setting the same manager to all docs, e.g.:

{events, [
  {my_doc_1, my_event_manager},
  {my_doc_2, my_event_manager},
  {my_doc_3, my_event_manager},
  . . .
]}

So the only case we still need to solve is: "Several event managers added to one doc". So the other option might be:

{events, [
  {my_doc_1, my_event_manager},
  {my_doc_2, my_event_manager},
  {my_doc_3, [my_event_manager, other_event_manager]},
  . . .
]}
elbrujohalcon commented 8 years ago

I like your idea, @cabol and I would just add the option to specify '_' as the doc name to represent all docs…

{events, [
  {'_', [my_first_global_event_manager, my_second_global_event_manager]},
  {my_doc_1, my_event_manager},
  {my_doc_2, my_event_manager},
  {my_doc_3, [my_event_manager, other_event_manager]},
  . . .
]}
cabol commented 8 years ago

Perfect!