diff --git a/src/dipdup/datasources/evm_node.py b/src/dipdup/datasources/evm_node.py index 55871d502..064b8f2c8 100644 --- a/src/dipdup/datasources/evm_node.py +++ b/src/dipdup/datasources/evm_node.py @@ -102,7 +102,7 @@ async def initialize(self) -> None: self.set_sync_level(None, level) async def run(self) -> None: - if self.realtime: + if self.ws_available: await asyncio.gather( self._ws_loop(), self._emitter_loop(), @@ -181,11 +181,11 @@ async def _ws_loop(self) -> None: raise DatasourceError('Websocket connection failed', self.name) @property - def realtime(self) -> bool: + def ws_available(self) -> bool: return self._config.ws_url is not None async def subscribe(self) -> None: - if not self.realtime: + if not self.ws_available: return missing_subscriptions = self._subscriptions.missing_subscriptions diff --git a/src/dipdup/datasources/starknet_node.py b/src/dipdup/datasources/starknet_node.py index 683de3ae3..90debe972 100644 --- a/src/dipdup/datasources/starknet_node.py +++ b/src/dipdup/datasources/starknet_node.py @@ -33,7 +33,7 @@ async def initialize(self) -> None: self.set_sync_level(None, level) async def run(self) -> None: - if self.realtime: + if self.ws_available: raise NotImplementedError('Realtime mode is not supported yet; remove `ws_url` from datasource config') while True: @@ -42,11 +42,11 @@ async def run(self) -> None: await asyncio.sleep(self._http_config.polling_interval) @property - def realtime(self) -> bool: + def ws_available(self) -> bool: return self._config.ws_url is not None async def subscribe(self) -> None: - if self.realtime: + if self.ws_available: raise NotImplementedError('Realtime mode is not supported yet; remove `ws_url` from datasource config') async def get_head_level(self) -> int: diff --git a/src/dipdup/datasources/substrate_node.py b/src/dipdup/datasources/substrate_node.py index 5f41cf739..62ade832b 100644 --- a/src/dipdup/datasources/substrate_node.py +++ b/src/dipdup/datasources/substrate_node.py @@ -114,7 +114,7 @@ def __init__(self, config: SubstrateNodeDatasourceConfig) -> None: self._on_event_callbacks: set[EventCallback] = set() async def run(self) -> None: - if self.realtime: + if self.ws_available: await asyncio.gather( self._ws_loop(), self._emitter_loop(), @@ -152,11 +152,11 @@ async def _ws_loop(self) -> None: raise DatasourceError('Websocket connection failed', self.name) @property - def realtime(self) -> bool: + def ws_available(self) -> bool: return self._config.ws_url is not None async def subscribe(self) -> None: - if not self.realtime: + if not self.ws_available: return missing_subscriptions = self._subscriptions.missing_subscriptions diff --git a/src/dipdup/dipdup.py b/src/dipdup/dipdup.py index a16ee97c3..859ab6f6f 100644 --- a/src/dipdup/dipdup.py +++ b/src/dipdup/dipdup.py @@ -230,11 +230,11 @@ async def _update_metrics(self) -> None: active, synced, realtime = 0, 0, 0 levels_indexed, levels_total, levels_interval = 0, 0, 0 for index in self._indexes.values(): - # FIXME: We don't remove disabled indexes from dispatcher anymore - active += 1 - if index.synchronized: + if index.is_active: + active += 1 + if index.is_synchronized: synced += 1 - if index.realtime: + if index.is_realtime: realtime += 1 try: diff --git a/src/dipdup/index.py b/src/dipdup/index.py index c5c4c5546..d9122adc3 100644 --- a/src/dipdup/index.py +++ b/src/dipdup/index.py @@ -190,11 +190,15 @@ def state(self) -> models.Index: return self._state @property - def synchronized(self) -> bool: + def is_active(self) -> bool: + return self.state.status not in (IndexStatus.disabled, IndexStatus.failed) + + @property + def is_synchronized(self) -> bool: return self.state.status == IndexStatus.realtime @property - def realtime(self) -> bool: + def is_realtime(self) -> bool: return self.state.status == IndexStatus.realtime and not self.queue def get_sync_level(self) -> int: