Skip to content

Commit 83fa816

Browse files
Retry on pysignalr's ConnectionError (#196)
* Retry on pysignalr ConnectionError * Changelog * Bump
1 parent aa6bc02 commit 83fa816

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
44

55
## [unreleased]
66

7-
## Added
7+
### Added
88

99
* tzkt: Added optional `delegate_address` and `delegate_alias` fields to `OperationData`.
1010

11-
## Fixed
11+
### Fixed
1212

13-
* tzkt: Fixed incorrect parsing of `OperationData.amount` field.
13+
* tzkt: Fixed crash due to unprocessed pysignalr exception.
14+
* tzkt: Fixed parsing `OperationData.amount` field.
1415

1516
## 4.0.1 - 2021-12-30
1617

17-
## Fixed
18+
### Fixed
1819

1920
* codegen: Fixed generating storage typeclasses with `Union` fields.
2021
* codegen: Fixed preprocessing contract JSONSchema.
2122
* index: Fixed processing reindexing reason saved in the database.
2223
* tzkt: Fixed processing operations with default entrypoint and empty parameter.
2324
* tzkt: Fixed crash while recursively applying bigmap diffs to the storage.
2425

25-
## Performance
26+
### Performance
2627

2728
* tzkt: Increased speed of applying bigmap diffs to operation storage.
2829

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.ONESHELL:
2-
.PHONY: test
2+
.PHONY: test build
33
.DEFAULT_GOAL: all
44

55
DEV=1

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ datamodel-code-generator = "^0.11.1"
3232
fcache = "^0.4.7"
3333
pydantic = "^1.8.1"
3434
pyhumps = "^3.0.2"
35-
pysignalr = "^0.1.0"
35+
pysignalr = "^0.1.1"
3636
pytezos = {version = "^3.2.4", optional = true}
3737
python-dotenv = "^0.18.0"
3838
"ruamel.yaml" = "^0.17.2"

src/dipdup/datasources/tzkt/datasource.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import sys
34
from asyncio import Event
45
from asyncio import create_task
56
from asyncio import gather
@@ -24,6 +25,7 @@
2425

2526
from aiohttp import ClientResponseError
2627
from pysignalr.client import SignalRClient
28+
from pysignalr.exceptions import ConnectionError as WebsocketConnectionError
2729
from pysignalr.messages import CompletionMessage # type: ignore
2830
from pysignalr.transport.websocket import DEFAULT_MAX_SIZE
2931

@@ -594,7 +596,19 @@ def _get_ws_client(self) -> SignalRClient:
594596

595597
async def run(self) -> None:
596598
self._logger.info('Establishing realtime connection')
597-
tasks = [create_task(self._get_ws_client().run())]
599+
ws = self._get_ws_client()
600+
601+
async def _wrapper():
602+
retry_sleep = self._http_config.retry_sleep
603+
for _ in range(self._http_config.retry_count or sys.maxsize):
604+
try:
605+
await ws.run()
606+
except WebsocketConnectionError as e:
607+
self._logger.error('Websocket connection error: %s', e)
608+
await asyncio.sleep(retry_sleep)
609+
retry_sleep *= self._http_config.retry_multiplier
610+
611+
tasks = [create_task(_wrapper())]
598612

599613
if self._watchdog:
600614
tasks.append(create_task(self._watchdog.run()))

0 commit comments

Comments
 (0)