Add time monitoring loop into service.
This commit is contained in:
parent
317188e3e7
commit
697006278f
|
@ -226,6 +226,7 @@ proc pollForTime(service: MonitorServiceRef,
|
||||||
timeOffset = tres.get()
|
timeOffset = tres.get()
|
||||||
timeDuration = nanoseconds(abs(tres.get()))
|
timeDuration = nanoseconds(abs(tres.get()))
|
||||||
soffset = if tres.get() < 0: "-" & $timeDuration else: $timeDuration
|
soffset = if tres.get() < 0: "-" & $timeDuration else: $timeDuration
|
||||||
|
debug "Remote beacon time offset received", offset = soffset
|
||||||
if timeDuration >= WARNING_TIME_OFFSET:
|
if timeDuration >= WARNING_TIME_OFFSET:
|
||||||
warn "Remote beacon node has significant time offset", offset = soffset
|
warn "Remote beacon node has significant time offset", offset = soffset
|
||||||
elif timeDuration >= NOTICE_TIME_OFFSET:
|
elif timeDuration >= NOTICE_TIME_OFFSET:
|
||||||
|
@ -311,18 +312,22 @@ proc mainLoop(service: MonitorServiceRef) {.async.} =
|
||||||
|
|
||||||
var breakLoop = false
|
var breakLoop = false
|
||||||
var blockMonitoringLoopFut: Future[void]
|
var blockMonitoringLoopFut: Future[void]
|
||||||
|
var timeMonitoringLoopFut: Future[void]
|
||||||
|
|
||||||
while not(breakLoop):
|
while not(breakLoop):
|
||||||
breakLoop =
|
breakLoop =
|
||||||
try:
|
try:
|
||||||
blockMonitoringLoopFut = service.blockMonitoringLoop()
|
blockMonitoringLoopFut = service.blockMonitoringLoop()
|
||||||
await allFutures(blockMonitoringLoopFut)
|
timeMonitoringLoopFut = service.timeMonitoringLoop()
|
||||||
|
await allFutures(blockMonitoringLoopFut, timeMonitoringLoopFut)
|
||||||
false
|
false
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
debug "Service interrupted"
|
debug "Service interrupted"
|
||||||
var pending: seq[Future[void]]
|
var pending: seq[Future[void]]
|
||||||
if not(blockMonitoringLoopFut.finished()):
|
if not(blockMonitoringLoopFut.finished()):
|
||||||
pending.add(blockMonitoringLoopFut.cancelAndWait())
|
pending.add(blockMonitoringLoopFut.cancelAndWait())
|
||||||
|
if not(timeMonitoringLoopFut.finished()):
|
||||||
|
pending.add(timeMonitoringLoopFut.cancelAndWait())
|
||||||
await allFutures(pending)
|
await allFutures(pending)
|
||||||
true
|
true
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
|
|
Loading…
Reference in New Issue