-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separation of node health and initialization state from rln_relay sta…
…tus. Make (only) health endpoint avail early and install others in the last stage of node setup.
- Loading branch information
1 parent
e61e4ff
commit 1d9a5ef
Showing
5 changed files
with
203 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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 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 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,65 @@ | ||
when (NimMajor, NimMinor) < (1, 4): | ||
{.push raises: [Defect].} | ||
else: | ||
{.push raises: [].} | ||
|
||
import std/[options, sequtils, strutils, tables], chronos | ||
|
||
import waku_node, ../waku_rln_relay | ||
|
||
type | ||
HealthStatus* = enum | ||
INITIALIZING | ||
SYNCHRONIZING | ||
READY | ||
NOT_READY | ||
NOT_MOUNTED | ||
SHUTTING_DOWN | ||
|
||
HealtReport* = object | ||
nodeHealth*: HealthStatus | ||
protocolHealth*: Table[string, HealthStatus] | ||
|
||
WakuNodeHealthMonitor* = ref object | ||
nodeHealth: HealthStatus | ||
node: Option[WakuNode] | ||
|
||
proc `$`*(t: HealthStatus): string = | ||
result = | ||
case t | ||
of INITIALIZING: "Initializing" | ||
of SYNCHRONIZING: "Synchronizing" | ||
of READY: "Ready" | ||
of NOT_READY: "Not Ready" | ||
of NOT_MOUNTED: "Not Mounted" | ||
of SHUTTING_DOWN: "Shutting Down" | ||
|
||
const FutIsReadyTimout = 5.seconds | ||
|
||
proc getNodeHealthReport*(hm: WakuNodeHealthMonitor): Future[HealtReport] {.async.} = | ||
result.nodeHealth = hm.nodeHealth | ||
|
||
if hm.node.isSome(): ## and not hm.node.get().wakuRlnRelay == nil: | ||
let getRlnRelayHealth = proc(): Future[HealthStatus] {.async.} = | ||
let isReadyStateFut = hm.node.get().wakuRlnRelay.isReady() | ||
if not await isReadyStateFut.withTimeout(FutIsReadyTimout): | ||
return HealthStatus.NOT_READY | ||
|
||
try: | ||
if not isReadyStateFut.completed(): | ||
return HealthStatus.NOT_READY | ||
elif isReadyStateFut.read(): | ||
return HealthStatus.READY | ||
|
||
return HealthStatus.SYNCHRONIZING | ||
except: | ||
error "exception reading state: " & getCurrentExceptionMsg() | ||
return HealthStatus.NOT_READY | ||
|
||
result.protocolHealth["Rln Relay"] = await getRlnRelayHealth() | ||
|
||
proc setNode*(hm: WakuNodeHealthMonitor, node: WakuNode) = | ||
hm.node = some(node) | ||
|
||
proc setOverallHealth*(hm: WakuNodeHealthMonitor, health: HealthStatus) = | ||
hm.nodeHealth = health |
Oops, something went wrong.