commit c0e4ab5c2cd361d24da5a080ac79021b6a251d14
parent 66c0fd0b51089cf437ebfcbcf835100a0c50c3dd
Author: nolash <dev@holbrook.no>
Date: Wed, 3 Feb 2021 21:10:08 +0100
Loop runs!
Diffstat:
5 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/cic_syncer/backend.py b/cic_syncer/backend.py
@@ -2,8 +2,8 @@
import logging
# local imports
-from cic_eth.db.models.sync import BlockchainSync
-from cic_eth.db.models.base import SessionBase
+from cic_syncer.db.models.sync import BlockchainSync
+from cic_syncer.db.models.base import SessionBase
logg = logging.getLogger()
diff --git a/cic_syncer/db/models/sync.py b/cic_syncer/db/models/sync.py
@@ -21,7 +21,7 @@ class BlockchainSync(SessionBase):
:param block_target: Block number to sync until, inclusive
:type block_target: number
"""
- __tablename__ = 'blockchain_sync'
+ __tablename__ = 'chain_sync'
blockchain = Column(String)
block_start = Column(Integer)
diff --git a/cic_syncer/driver.py b/cic_syncer/driver.py
@@ -1,6 +1,7 @@
# standard imports
import uuid
import logging
+import time
# third-party imports
import websockets
@@ -10,6 +11,8 @@ logg = logging.getLogger()
class Syncer:
+ running_global = True
+
def __init__(self, backend):
self.cursor = None
self.running = True
@@ -30,7 +33,7 @@ class Syncer:
class MinedSyncer(Syncer):
def __init__(self, backend):
- super(HeadSyncer, self).__init__(backend)
+ super(MinedSyncer, self).__init__(backend)
def loop(self, interval):
@@ -38,6 +41,7 @@ class MinedSyncer(Syncer):
getter = self.backend.connect()
logg.debug('loop execute')
e = self.get(getter)
+ time.sleep(interval)
class HeadSyncer(MinedSyncer):
diff --git a/cic_syncer/runnable/tracker.py b/cic_syncer/runnable/tracker.py
@@ -13,6 +13,8 @@ from cic_syncer.driver import HeadSyncer
from cic_syncer.db import dsn_from_config
from cic_syncer.db.models.base import SessionBase
from cic_syncer.client.evm.websocket import EVMWebsocketClient
+from cic_syncer.backend import SyncerBackend
+from cic_syncer.error import LoopDone
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -92,24 +94,15 @@ re_websocket = re.compile('^wss?://')
re_http = re.compile('^https?://')
c = EVMWebsocketClient(config.get('ETH_PROVIDER'))
chain = args.i
-#blockchain_provider = config.get('ETH_PROVIDER')
-#if re.match(re_websocket, blockchain_provider) != None:
-# blockchain_provider = WebsocketProvider(blockchain_provider)
-#elif re.match(re_http, blockchain_provider) != None:
-# blockchain_provider = HTTPProvider(blockchain_provider)
-#else:
-# raise ValueError('unknown provider url {}'.format(blockchain_provider))
-#
+
def main():
- #chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
- #c = RpcClient(chain_spec)
block_offset = c.block_number()
logg.debug('block offset {}'.format(block_offset))
- return
- syncer = SyncerBackend.live(chain, block_offset+1)
+ syncer_backend = SyncerBackend.live(chain, block_offset+1)
+ syncer = HeadSyncer(syncer_backend)
for cb in config.get('TASKS_SYNCER_CALLBACKS', '').split(','):
task_split = cb.split(':')
diff --git a/config/syncer.ini b/config/syncer.ini
@@ -0,0 +1,2 @@
+[syncer]
+loop_interval = 1