feat: decouple round tracker from API routes #292
Merged
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.
feat: decouple round tracker from API routes
Rework API handlers to get the current round from the database.
Benefits:
This commit fixes the long-standing bug where the REST API returned different current round depending on which worker process received the request. This was caused by different timing when each worker process detected a new RoundStarted event.
The new architecture allows us to further decouple the round tracker from the API handler. We can run it in background to not block process startup or even extract it into a standalone service.
Downsides:
POST /measurements
GET /rounds/current
Note: The next commit reworks the query recording a new measurement to obtain the current round number in a sub-query of the
INSERT
statement.perf: inline
getCurrentRound()
Rework the query inserting new measurements to fetch the current round as part of the single INSERT statement.
Inline
getCurrentRound()
implementation into the single remaining place calling it - the handler forGET /rounds/current
.Links: