Expand description
§Implementation of the GET /health/started endpoint
This module provides an HTTP endpoint to monitor the start of the Cat Gateway service, which depends on multiple parameters. It uses atomic booleans to track the status of the service and its dependencies.
§Key Features
-
Atomic Booleans for Initialization:
STARTED: Indicates whether the service has fully initialized. It defaults tofalseon startup and can only transition totrueonce all required conditions are met. Once set totrue, it cannot be changed back tofalse.LIVE_INDEX_DBandLIVE_EVENT_DB: Track the connection status of the Index DB and Event DB, respectively. Both default tofalseon startup and are set totrueonce a successful connection is established.- A third atomic boolean (e.g.,
INITIAL_FOLLOWER_TIP_REACHED) is used to track whether the chain indexer has reached the tip of the chain for the first time. This also defaults tofalseand is set totrueonce the condition is met.
-
Initialization Logic:
- On startup, the service attempts to connect to both databases (Index DB and Event
DB). It will keep retrying until both connections are successful. Once both
databases are connected, their respective flags (
LIVE_INDEX_DBandLIVE_EVENT_DB) are set totrue. - The
STARTEDflag is set totrueonly when all three conditions are met simultaneously:LIVE_INDEX_DBistrue.LIVE_EVENT_DBistrue.INITIAL_FOLLOWER_TIP_REACHEDistrue.
- Once
STARTEDis set totrue, it cannot be changed back tofalse.
- On startup, the service attempts to connect to both databases (Index DB and Event
DB). It will keep retrying until both connections are successful. Once both
databases are connected, their respective flags (
-
Response Logic:
- If
STARTEDistrue, the endpoint returns a204 No Contentresponse, indicating that the service is fully initialized and operational. - If
STARTEDisfalse, the endpoint returns a503 Service Unavailableresponse, indicating that the service is not yet ready to handle requests.
- If
§How It Works
- On startup, the service attempts to connect to the Index DB and Event DB. It retries
until both connections are successful. Once connected, their respective flags
(
LIVE_INDEX_DBandLIVE_EVENT_DB) are set totrue. - The chain indexer monitors the blockchain and sets
INITIAL_FOLLOWER_TIP_REACHEDtotrueonce it reaches the tip of the chain for the first time. - When all three flags (
LIVE_INDEX_DB,LIVE_EVENT_DB, andINITIAL_FOLLOWER_TIP_REACHED) aretrue, theSTARTEDflag is set totrue. - Once
STARTEDistrue, the endpoint will always respond with204 No Content. - If
STARTEDisfalse, the endpoint will respond with503 Service Unavailable.
§Example Scenarios
-
Startup Phase:
- The service is starting up.
LIVE_INDEX_DB,LIVE_EVENT_DB, andINITIAL_FOLLOWER_TIP_REACHEDare allfalse.STARTEDisfalse.- The endpoint returns
503 Service Unavailable.
-
Databases Connected, Indexer Not Ready:
- The Index DB and Event DB are connected (
LIVE_INDEX_DBandLIVE_EVENT_DBaretrue). - The chain indexer has not yet reached the tip of the chain
(
INITIAL_FOLLOWER_TIP_REACHEDisfalse). STARTEDisfalse.- The endpoint returns
503 Service Unavailable.
- The Index DB and Event DB are connected (
-
All Conditions Met:
- The Index DB and Event DB are connected (
LIVE_INDEX_DBandLIVE_EVENT_DBaretrue). - The chain indexer has reached the tip of the chain
(
INITIAL_FOLLOWER_TIP_REACHEDistrue). STARTEDis set totrue.- The endpoint returns
204 No Content.
- The Index DB and Event DB are connected (
-
After Initialization:
- All flags (
LIVE_INDEX_DB,LIVE_EVENT_DB,INITIAL_FOLLOWER_TIP_REACHED, andSTARTED) aretrue. - The endpoint continues to return
204 No Content.
- All flags (
§Notes
- All booleans are atomic, meaning they are thread-safe and can be accessed concurrently without issues.
- Once
STARTEDis set totrue, it cannot be reverted, ensuring that the service remains in a consistent state after initialization.
This endpoint is useful for monitoring the initialization status of a service that depends on multiple external systems, ensuring that the service only becomes available once all dependencies are ready.
Enums§
- Responses 🔒
- Endpoint responses.
Functions§
- endpoint 🔒
- GET /health/started
Type Aliases§
- AllResponses 🔒
- All responses.