1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/db
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
..
access-store.ts refactor: clean up deprecated permissions (#4124) 2023-06-30 11:15:11 +01:00
account-store.ts fix: add confirmation to disable password login (#3829) 2023-05-23 15:56:34 +01:00
addon-store.ts OpenAPI: addon operations (#3421) 2023-04-18 10:50:34 +00:00
api-token-store.ts chore: add another migration that remigrates the proper way (#3719) 2023-05-11 15:33:04 +02:00
client-applications-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
client-instance-store.ts Remove timeout from store (#3018) 2023-01-30 12:01:44 +01:00
client-metrics-store-v2.ts chore: remove variant metrics flag (#4042) 2023-06-21 15:55:21 +03:00
context-field-store.ts feat: context field usage frontend (#3938) 2023-06-12 10:55:58 +03:00
db-pool.ts feat: add "application_name" as an optional DB option #1170 (#1478) 2022-04-07 20:55:56 +02:00
db.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
environment-store.ts feat: add max order to environments (#3988) 2023-06-15 12:21:35 +03:00
event-store.test.ts feat: add event search endpoint (#1893) 2022-08-09 16:14:50 +02:00
event-store.ts 1-1049 Emit events after db transaction is complete (#4174) 2023-07-10 08:43:22 +02:00
favorite-features-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
favorite-projects-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
feature-environment-store.ts export queries use order by feature name (#3051) 2023-02-06 15:46:25 +01:00
feature-strategy-store.test.ts feat: add instance stats to version check (#3835) 2023-06-13 15:54:20 +02:00
feature-strategy-store.ts feat: add instance stats to version check (#3835) 2023-06-13 15:54:20 +02:00
feature-tag-store.ts fix: fix bulk removal of tags (#3651) 2023-04-28 14:49:34 +03:00
feature-toggle-client-store.ts refactor: use requestType instead of isAdmin, optionalIncludes (#4115) 2023-07-05 09:32:42 +02:00
feature-toggle-store.ts feat: save memory on reading stats (#3472) 2023-04-06 15:34:08 +02:00
feature-type-store.ts feat: Create project service di (#3326) 2023-03-15 16:46:41 +01:00
group-store.ts fix: creating groups should work without users (#4033) 2023-06-21 14:44:43 +03:00
index.ts feat: usage on context fields in list (#3906) 2023-06-06 13:59:41 +03:00
pat-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
project-stats-store.ts refactor: switching to new stats calculations (#3477) 2023-04-10 09:50:39 +02:00
project-store.ts fix: add createdAt in projects API response (#3929) 2023-06-09 14:18:38 +00:00
public-signup-token-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
reset-token-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
role-store.ts feat: custom root roles (#3975) 2023-06-14 14:40:40 +01:00
segment-store.test.ts ux: return better error message if a segment doesn't exist (#4122) 2023-06-30 09:02:24 +00:00
segment-store.ts ux: return better error message if a segment doesn't exist (#4122) 2023-06-30 09:02:24 +00:00
session-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
setting-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
strategy-store.ts feat: add title to strategy (#3510) 2023-04-18 08:59:02 +02:00
tag-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
tag-type-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
transaction.ts feat: oss import (#3123) 2023-02-16 08:08:51 +01:00
user-feedback-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
user-splash-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00
user-store.ts feat: allow every store to participate in transaction (#3016) 2023-01-30 09:02:44 +01:00