Skip to content

Commit

Permalink
auto reconnect and fail and report on error
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Apr 22, 2022
1 parent 68000db commit 113f3f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 3 additions & 9 deletions iscc_observer_evm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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__":
Expand Down
4 changes: 4 additions & 0 deletions iscc_observer_evm/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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


Expand Down

0 comments on commit 113f3f3

Please sign in to comment.