Skip to content

Commit

Permalink
vars naming
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Dec 19, 2024
1 parent 7fe38a4 commit 2caa2ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/dipdup/datasources/evm_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/dipdup/datasources/starknet_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/dipdup/datasources/substrate_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/dipdup/dipdup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/dipdup/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2caa2ef

Please sign in to comment.