Skip to content

Commit

Permalink
(feat) Remove aiocron dependency. Use pure asyncio task to update the…
Browse files Browse the repository at this point in the history
… timeout height
  • Loading branch information
abel committed Oct 16, 2023
1 parent 20c966b commit 33e4b01
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
run-tests:
strategy:
matrix:
python: ["3.9", "3.10", "3.11"]
python: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ poetry run pytest -v
```

### Changelogs
**0.10**
* Remove `aiocron` dependency. Use plain asyncio tasks to solve the timeout height synchronization

**0.9.3**
* Updated TIA/USDT-30NOV2023 market id in denoms_mainnet.ini file

Expand Down
104 changes: 9 additions & 95 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from decimal import Decimal
from typing import Coroutine, Dict, List, Optional, Tuple, Union

import aiocron
import grpc

from pyinjective.composer import Composer
Expand Down Expand Up @@ -108,13 +107,8 @@ def __init__(
)
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(self.explorer_channel)

# timeout height update routine
self.cron = aiocron.crontab(
"* * * * * */{}".format(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL),
func=self.sync_timeout_height,
args=(),
start=True,
)
self._timeout_height_sync_task = None
self._initialize_timeout_height_sync_task()

self._tokens_and_markets_initialization_lock = asyncio.Lock()
self._tokens: Optional[Dict[str, Token]] = None
Expand Down Expand Up @@ -163,11 +157,11 @@ async def get_tx(self, tx_hash):

async def close_exchange_channel(self):
await self.exchange_channel.close()
self.cron.stop()
self._cancel_timeout_height_sync_task()

Check warning on line 160 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L160

Added line #L160 was not covered by tests

async def close_chain_channel(self):
await self.chain_channel.close()
self.cron.stop()
self._cancel_timeout_height_sync_task()

Check warning on line 164 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L164

Added line #L164 was not covered by tests

async def sync_timeout_height(self):
try:
Expand Down Expand Up @@ -1009,3 +1003,17 @@ def _chain_cookie_metadata_requestor(self) -> Coroutine:
def _exchange_cookie_metadata_requestor(self) -> Coroutine:
request = exchange_meta_rpc_pb.VersionRequest()
return self.stubMeta.Version(request).initial_metadata()

def _initialize_timeout_height_sync_task(self):
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.create_task(self._timeout_height_sync_process())

async def _timeout_height_sync_process(self):
while True:
await self.sync_timeout_height()
await asyncio.sleep(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL)

def _cancel_timeout_height_sync_task(self):
if self._timeout_height_sync_task is not None:
self._timeout_height_sync_task.cancel()

Check warning on line 1018 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L1018

Added line #L1018 was not covered by tests
self._timeout_height_sync_task = None
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "injective-py"
version = "0.9.3"
version = "0.10dev"
description = "Injective Python SDK, with Exchange API Client"
authors = ["Injective Labs <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -22,7 +22,6 @@ include = [

[tool.poetry.dependencies]
python = "^3.9"
aiocron = "*"
aiohttp = "*"
asyncio = "*"
bech32 = "*"
Expand Down

0 comments on commit 33e4b01

Please sign in to comment.