diff --git a/fluffy/tools/portal_bridge/portal_bridge.nim b/fluffy/tools/portal_bridge/portal_bridge.nim index 40b046992..4f7f69755 100644 --- a/fluffy/tools/portal_bridge/portal_bridge.nim +++ b/fluffy/tools/portal_bridge/portal_bridge.nim @@ -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() @@ -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() diff --git a/fluffy/tools/portal_bridge/portal_bridge_beacon.nim b/fluffy/tools/portal_bridge/portal_bridge_beacon.nim index 486ed0bbe..6863f17fd 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_beacon.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_beacon.nim @@ -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). @@ -465,6 +465,3 @@ proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} = ) asyncSpawn runOnSlotLoop() - - while true: - poll() diff --git a/fluffy/tools/portal_bridge/portal_bridge_history.nim b/fluffy/tools/portal_bridge/portal_bridge_history.nim index 116ba1ab4..8fe3cdec8 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_history.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_history.nim @@ -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). @@ -543,6 +543,3 @@ proc runHistory*(config: PortalBridgeConf) = asyncSpawn bridge.runBackfillLoop( config.era1Dir.string, config.startEra, config.endEra ) - - while true: - poll()