From 113f3f3849a97faf2dd3f3fedc1bd844e687b66f Mon Sep 17 00:00:00 2001 From: Titusz Pan Date: Fri, 22 Apr 2022 16:00:48 +0200 Subject: [PATCH] auto reconnect and fail and report on error --- iscc_observer_evm/__main__.py | 12 +++--------- iscc_observer_evm/chain.py | 4 ++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/iscc_observer_evm/__main__.py b/iscc_observer_evm/__main__.py index aea5cca..2fe0920 100644 --- a/iscc_observer_evm/__main__.py +++ b/iscc_observer_evm/__main__.py @@ -4,7 +4,6 @@ import click import iscc_core as ic from loguru import logger as log -from sentry_sdk import capture_exception import iscc_observer_evm as evm @@ -40,12 +39,12 @@ def update(): f"registry out of sync at height {head.block_height} hash {head.block_hash}" ) rollback() - return - start_height = head.block_height if head else 0 + start_height = head.block_height + 1 if head else 0 for event in evm.chain().events(from_block=start_height): block = evm.chain().block(event.blockNumber) + log.info(f"new event for {event.args.iscc}") declaration = dict( timestamp=block.timestamp, chain_id=evm.config.chain_id, @@ -96,12 +95,7 @@ def main(envfile): while True: time.sleep(evm.config.update_interval) - try: - update() - except Exception as e: - if evm.config.sentry_dsn: - capture_exception(e) - log.error(e) + update() if __name__ == "__main__": diff --git a/iscc_observer_evm/chain.py b/iscc_observer_evm/chain.py index 6018a85..e5713ee 100644 --- a/iscc_observer_evm/chain.py +++ b/iscc_observer_evm/chain.py @@ -4,6 +4,7 @@ from web3 import Web3 from web3.middleware import geth_poa_middleware import iscc_observer_evm as evm +from loguru import logger as log __all__ = ["chain"] @@ -16,6 +17,9 @@ def chain(): global ch if ch is None: ch = Chain() + if not ch.w3.isConnected(): + log.error(f"Connection failed to {evm.config.web3_url}, reconnecting") + ch = Chain() return ch