Skip to content

Commit

Permalink
Handle shutdown in history and beacon bridges.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jan 15, 2025
1 parent 7785639 commit 47704bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
20 changes: 14 additions & 6 deletions fluffy/tools/portal_bridge/portal_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ type PortalBridgeStatus = enum
Running
Stopping

template pollWhileRunning(status: PortalBridgeStatus) =
while status == PortalBridgeStatus.Running:
try:
poll()
except CatchableError as e:
warn "Exception in poll()", exc = e.name, err = e.msg

when isMainModule:
{.pop.}
let config = PortalBridgeConf.load()
Expand Down Expand Up @@ -88,15 +95,16 @@ when isMainModule:
case config.cmd
of PortalBridgeCmd.beacon:
runBeacon(config)

pollWhileRunning(bridgeStatus)
# TODO: Implement stop/cleanup for beacon bridge
of PortalBridgeCmd.history:
runHistory(config)

pollWhileRunning(bridgeStatus)
# TODO: Implement stop/cleanup for history bridge
of PortalBridgeCmd.state:
let bridge = waitFor runState(config)

while bridgeStatus == PortalBridgeStatus.Running:
try:
poll()
except CatchableError as e:
warn "Exception in poll()", exc = e.name, err = e.msg

pollWhileRunning(bridgeStatus)
waitFor bridge.stop()
5 changes: 1 addition & 4 deletions fluffy/tools/portal_bridge/portal_bridge_beacon.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fluffy
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Copyright (c) 2023-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -465,6 +465,3 @@ proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
)

asyncSpawn runOnSlotLoop()

while true:
poll()
5 changes: 1 addition & 4 deletions fluffy/tools/portal_bridge/portal_bridge_history.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fluffy
# Copyright (c) 2024 Status Research & Development GmbH
# Copyright (c) 2024-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -543,6 +543,3 @@ proc runHistory*(config: PortalBridgeConf) =
asyncSpawn bridge.runBackfillLoop(
config.era1Dir.string, config.startEra, config.endEra
)

while true:
poll()

0 comments on commit 47704bb

Please sign in to comment.