1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/services
Thomas Heartman d60e505a40
1-1049 Emit events after db transaction is complete (#4174)
This PR fixes an issue where events generated during a db transaction
would get published before the transaction was complete. This caused
errors in some of our services that expected the data to be stored
before the transaction had been commited. Refer to [linear issue
1-1049](https://linear.app/unleash/issue/1-1049/event-emitter-should-emit-events-after-db-transaction-is-commited-not)
for more info.

Fixes 1-1049.

## Changes

The most important change here is that the `eventStore` no longer emits
events when they happen (because that can be in the middle of a
transaction). Instead, events are stored with a new `announced` column.
The new event announcer service runs on a schedule (every second) and
publishes any new events that have not been published.

Parts of the code have largely been lifted from the
`client-application-store`, which uses a similar logic.

I have kept the emitting of the event within the event store because a
lot of other services listen to events from this store, so removing that
would require a large rewrite. It's something we could look into down
the line, but it seems like too much of a change to do right now.

## Discussion

### Terminology:

Published vs announced? We should settle on one or the other. Announced
is consistent with the client-application store, but published sounds
more fitting for events.

### Publishing and marking events as published

The current implementation fetches all events that haven't been marked
as announced, sets them as announced, and then emits them. It's possible
that Unleash would crash in the interim or something else might happen,
causing the events not to get published. Maybe it would make sense to
just fetch the events and only mark them as published after the
announcement? On the other hand, that might get us into other problems.
Any thoughts on this would be much appreciated.
2023-07-10 08:43:22 +02:00
..
client-metrics
access-service.test.ts
access-service.ts
account-service.ts
addon-schema.ts
addon-service-test-simple-addon.ts
addon-service.test.ts
addon-service.ts
api-token-service.test.ts
api-token-service.ts
client-spec-service.test.ts
client-spec-service.ts
context-schema.ts
context-service.ts
edge-service.ts
email-service.test.ts
email-service.ts
environment-service.ts
event-announcer-service.ts
event-service.ts
favorites-service.ts
feature-tag-service.ts
feature-toggle-service.ts
feature-type-service.ts
group-service.ts
health-service.ts
index.ts
instance-stats-service.test.ts
instance-stats-service.ts
maintenance-service.test.ts
maintenance-service.ts
openapi-service.ts
pat-service.ts
project-health-service.ts
project-schema.ts
project-service.ts
proxy-service.ts
public-signup-token-service.ts
reset-token-service.ts
scheduler-service.test.ts
scheduler-service.ts
segment-schema.ts
segment-service.ts
session-service.ts
setting-service.ts
state-schema.ts
state-service-export-v1.json
state-service.test.ts
state-service.ts
state-util.ts
strategy-schema.ts
strategy-service.ts
tag-schema.test.ts
tag-schema.ts
tag-service.ts
tag-type-schema.test.ts
tag-type-schema.ts
tag-type-service.ts
user-feedback-service.ts
user-service.test.ts
user-service.ts
user-splash-service.ts
version-service.test.ts
version-service.ts