|
31 | 31 | from dipdup.enums import MessageType |
32 | 32 | from dipdup.models import BigMapAction, BigMapData, BlockData, HeadBlockData, OperationData, QuoteData |
33 | 33 | from dipdup.utils import split_by_chunks |
| 34 | +from dipdup.utils.watchdog import Watchdog |
34 | 35 |
|
35 | 36 | TZKT_ORIGINATIONS_REQUEST_LIMIT = 100 |
36 | 37 |
|
@@ -266,9 +267,11 @@ def __init__( |
266 | 267 | self, |
267 | 268 | url: str, |
268 | 269 | http_config: Optional[HTTPConfig] = None, |
| 270 | + watchdog: Optional[Watchdog] = None, |
269 | 271 | ) -> None: |
270 | 272 | super().__init__(url, self._default_http_config.merge(http_config)) |
271 | 273 | self._logger = logging.getLogger('dipdup.tzkt') |
| 274 | + self._watchdog = watchdog |
272 | 275 |
|
273 | 276 | self._transaction_subscriptions: Set[str] = set() |
274 | 277 | self._origination_subscriptions: bool = False |
@@ -546,11 +549,13 @@ def _get_ws_client(self) -> BaseHubConnection: |
546 | 549 | return self._ws_client |
547 | 550 |
|
548 | 551 | async def run(self) -> None: |
549 | | - """Main loop. Sync indexes via REST, start WS connection""" |
550 | | - self._logger.info('Starting datasource') |
| 552 | + self._logger.info('Establishing realtime connection') |
| 553 | + tasks = [asyncio.create_task(self._get_ws_client().start())] |
551 | 554 |
|
552 | | - self._logger.info('Starting websocket client') |
553 | | - await self._get_ws_client().start() |
| 555 | + if self._watchdog: |
| 556 | + tasks.append(asyncio.create_task(self._watchdog.run())) |
| 557 | + |
| 558 | + await asyncio.gather(*tasks) |
554 | 559 |
|
555 | 560 | async def _on_connect(self) -> None: |
556 | 561 | """Subscribe to all required channels on established WS connection""" |
@@ -680,6 +685,9 @@ async def _on_big_maps_message(self, message: List[Dict[str, Any]]) -> None: |
680 | 685 | async def _on_head_message(self, message: List[Dict[str, Any]]) -> None: |
681 | 686 | """Parse and emit raw head block from WS""" |
682 | 687 | async for data in self._extract_message_data(MessageType.head, message): |
| 688 | + if self._watchdog: |
| 689 | + self._watchdog.reset() |
| 690 | + |
683 | 691 | block = self.convert_head_block(data) |
684 | 692 | await self.emit_head(block) |
685 | 693 |
|
|
0 commit comments