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

Provide to(event_id) for reading events #528

Closed
anderslemke opened this issue Jan 12, 2019 · 7 comments
Closed

Provide to(event_id) for reading events #528

anderslemke opened this issue Jan 12, 2019 · 7 comments

Comments

@anderslemke
Copy link
Contributor

anderslemke commented Jan 12, 2019

In some cases, when replaying events, it's useful to replay until a certain event.

There already is the from(start) but I would also like to be able to say to(stop).

I would propose that the event used as the stop condition is not read.

I will be submitting a PR for this, but just wanted to air the thoughts here before starting working on it.

@anderslemke anderslemke changed the title Provide until(event_id) for reading events Provide to(event_id) for reading events Jan 13, 2019
@paneq
Copy link
Member

paneq commented Jan 14, 2019

In some cases, when replaying events, it's useful to replay until a certain event.

Could you elaborate on those cases?

@anderslemke
Copy link
Contributor Author

Yes. Of course 👍

In my case:

  • I publish all saved events to RabbitMQ.
  • handle events by consuming from RabbitMQ.

Let's say I want to send an email once when something happens. Also historically.

To do that; I would

  1. put the consumer that actually sends mail into production; BUT
  2. make sure it is not fetching events from RabbitMQ,
  3. let events queue up in RabbitMQ
  4. peek at the next event in RabbitMQ, and take note of the event_id for that event
  5. replay all events from :head to event_id and send mails accordingly.

When the replay is done, I start the consumer on RabbitMQ, and let it catch up, sending mails for whatever might have happened since the consumer was taken down.

Now I have handled all historical events, and I'm up to date, and haven't missed a mail.

@paneq
Copy link
Member

paneq commented Jan 14, 2019

a) don't you need idempotency in the event handler?
b) if you had idempotent event handler then you could queue all events anyway and it would skip already processed ones.

I am not saying we don't need to(). Just sharing general knowledge around such problems @anderslemke 🙂

@anderslemke
Copy link
Contributor Author

Thanks for sharing your knowledge @paneq .

Having an idempotent event handler would probably remove the need for both from()and to(). (Unless I'm missing some other use case for from() where idempotent event handling is not sufficient.)

But as you indicated, it's probably not the responsibility of this gem to mandate how you implement your event handlers. Idempotency is nice, but it's also more complex. And you might get similar and sufficient guaranties from other layers of your setup (RabbitMQ in our case).

IMHO this gem is about storing and reading events, and having a to()-method fits good with this responsibility.

@mostlyobvious
Copy link
Member

In some cases, when replaying events, it's useful to replay until a certain event.

I've seen one of such cases recently, replaying events from given range for handlers that did not execute (failure mode). Without to in API it had to be done on repository level, that is EventStore::Repository::Event.where("id > ? AND id < ?", ...). I think having Client API for this use case is good addition.

@mostlyobvious
Copy link
Member

I would propose that the event used as the stop condition is not read.

That seems to be consistent with from behavior 👍

@mostlyobvious
Copy link
Member

I will be submitting a PR for this, but just wanted to air the thoughts here before starting working on it.

Looking forward to merge it when ready :)

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

3 participants