Repository navigation
feat(storage): add eventStore.backend setting and a single event repository factory #806
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
Merged
cameri
merged 5 commits into
cameri:main
from
Anshumancanrock:feat/event-store-backend-setting
Oct 10, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
117e2db
feat(config): add eventStore.backend setting
Anshumancanrock 59d8f33
refactor: build every event repository through one factory
Anshumancanrock 028c1e3
feat(app): pick the event store once at startup and hand it to workers
Anshumancanrock f30021e
chore: add changeset for eventStore.backend
Anshumancanrock 7765b37
Merge branch 'main' into feat/event-store-backend-setting
Anshumancanrock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "nostream": minor | ||
| --- | ||
|
|
||
| feat(storage): add an `eventStore.backend` setting and build every event repository through one factory | ||
|
|
||
| Defaults to `postgres`, the only backend for now. The backend is read once at startup and passed to every worker. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/factories/controllers/get-admission-check-controller-factory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| import process from 'process' | ||
|
|
||
| import { getMasterDbClient, getReadReplicaDbClient } from '../database/client' | ||
| import { createEventRepository } from './event-repository-factory' | ||
| import { createSettings } from './settings-factory' | ||
| import { DvmJobRepository } from '../repositories/dvm-job-repository' | ||
| import { DvmOrchestratorWorker } from '../app/dvm-orchestrator-worker' | ||
| import { EventRepository } from '../repositories/event-repository' | ||
|
|
||
| export const dvmOrchestratorWorkerFactory = () => { | ||
| const dbClient = getMasterDbClient() | ||
| const readReplicaDbClient = getReadReplicaDbClient() | ||
| const dvmJobRepository = new DvmJobRepository(dbClient) | ||
| const eventRepository = new EventRepository(dbClient, readReplicaDbClient, createSettings) | ||
| const eventRepository = createEventRepository(dbClient, readReplicaDbClient) | ||
|
|
||
| return new DvmOrchestratorWorker(process, createSettings, dvmJobRepository, eventRepository) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { createSettings } from './settings-factory' | ||
| import { DatabaseClient } from '../@types/base' | ||
| import { EventRepository } from '../repositories/event-repository' | ||
| import { EventStoreBackend } from '../constants/base' | ||
| import { getEventStoreBackend } from '../utils/event-store' | ||
| import { IEventRepository } from '../@types/repositories' | ||
| import { Settings } from '../@types/settings' | ||
|
|
||
| export const createEventRepository = ( | ||
| masterDbClient: DatabaseClient, | ||
| readReplicaDbClient: DatabaseClient, | ||
| settings: () => Settings = createSettings, | ||
| ): IEventRepository => { | ||
| const backend = getEventStoreBackend(settings()) | ||
|
|
||
| switch (backend) { | ||
| case EventStoreBackend.POSTGRES: | ||
| return new EventRepository(masterDbClient, readReplicaDbClient, settings) | ||
| default: { | ||
| // exhaustiveness check | ||
| const unhandled: never = backend | ||
| throw new Error(`No event repository is available for eventStore.backend "${unhandled}"`) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import { getMasterDbClient, getReadReplicaDbClient } from '../database/client' | ||
| import { createEventRepository } from './event-repository-factory' | ||
| import { createSettings } from './settings-factory' | ||
| import { EventRepository } from '../repositories/event-repository' | ||
| import { MaintenanceService } from '../services/maintenance-service' | ||
|
|
||
| export const createMaintenanceService = () => { | ||
| return new MaintenanceService(new EventRepository(getMasterDbClient(), getReadReplicaDbClient()), createSettings) | ||
| return new MaintenanceService(createEventRepository(getMasterDbClient(), getReadReplicaDbClient()), createSettings) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import cluster from 'cluster' | ||
|
|
||
| import { EventStoreBackend } from '../constants/base' | ||
| import { Settings } from '../@types/settings' | ||
|
|
||
| // Set by the primary on every worker it forks. | ||
| export const EVENT_STORE_BACKEND_ENV = 'EVENT_STORE_BACKEND' | ||
|
|
||
| export const EVENT_STORE_BACKENDS: readonly EventStoreBackend[] = Object.values(EventStoreBackend) | ||
|
|
||
| export const isEventStoreBackend = (value: unknown): value is EventStoreBackend => | ||
| EVENT_STORE_BACKENDS.includes(value as EventStoreBackend) | ||
|
|
||
| const toEventStoreBackend = (value: unknown, source: string): EventStoreBackend => { | ||
| if (!isEventStoreBackend(value)) { | ||
| throw new Error(`Unsupported ${source} "${String(value)}". Supported backends: ${EVENT_STORE_BACKENDS.join(', ')}`) | ||
| } | ||
|
|
||
| return value | ||
| } | ||
|
|
||
| export const getConfiguredEventStoreBackend = (settings: Settings): EventStoreBackend => | ||
| toEventStoreBackend(settings.eventStore?.backend ?? EventStoreBackend.POSTGRES, 'eventStore.backend') | ||
|
|
||
| // Workers use the backend the primary resolved at startup; other processes read settings. | ||
| export const getEventStoreBackend = (settings: Settings): EventStoreBackend => { | ||
| const inherited = cluster.isWorker ? process.env[EVENT_STORE_BACKEND_ENV] : undefined | ||
|
|
||
| return inherited === undefined | ||
| ? getConfiguredEventStoreBackend(settings) | ||
| : toEventStoreBackend(inherited, EVENT_STORE_BACKEND_ENV) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventStore.backendnow needs a restart, but the settings PATCH API still labels ithot-reload.getSettingsReloadBehavioronly marksworkers.,payments, andnetwork.as restart-required, so clients receive the wrong guidance for this setting.Add the new setting to that helper and test its PATCH response. Only
postgresis supported today, so this is a non-blocking API guidance issue rather than an incorrect store switch.