diff --git a/src/dexorder/runner.py b/src/dexorder/runner.py index df5dd3b..287caba 100644 --- a/src/dexorder/runner.py +++ b/src/dexorder/runner.py @@ -4,7 +4,6 @@ from asyncio import Queue from datetime import datetime from typing import Callable, Union, Any, Iterable -from sqlalchemy.sql.functions import current_timestamp from web3.contract.contract import ContractEvents from web3.exceptions import LogTopicError, MismatchedABI # noinspection PyPackageRequirements @@ -118,6 +117,7 @@ class BlockStateRunner: await self.queue.put(head["hash"]) if not self.running: break + await async_yield() except (ConnectionClosedError, TimeoutError): pass finally: @@ -127,7 +127,7 @@ class BlockStateRunner: await w3ws.provider.disconnect() except Exception: pass - await async_yield() + log.debug('yield') log.debug('runner run_ws() exiting') @@ -183,15 +183,17 @@ class BlockStateRunner: while self.running: try: async with asyncio.timeout(1): # check running flag every second - start = datetime.now() head = await self.queue.get() except TimeoutError: + log.debug('timeout in runner') # 1 second has passed without a new head. Run the postprocess callbacks to check for activated time-based triggers if prev_head is not None: await self.handle_time_tick(head) else: try: + log.debug('handle head...') await self.handle_head(chain, head, w3) + log.debug('handled') prev_head = head except Exception as x: log.exception(x)