cic-tracker/cic_tracker/runnable/daemon.py

77 lines
2.0 KiB
Python
Raw Normal View History

2022-04-23 07:29:14 +02:00
# standard imports
import logging
import os
2022-04-23 11:34:30 +02:00
import datetime
2022-04-24 13:03:00 +02:00
import importlib
2022-04-24 23:16:33 +02:00
import sys
2022-04-23 07:29:14 +02:00
# external imports
2022-04-23 11:34:30 +02:00
from chainsyncer.error import SyncDone
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
2022-04-24 13:03:00 +02:00
2022-04-24 17:03:21 +02:00
# cic_eth legacy imports
2022-04-24 21:28:55 +02:00
import cic_base.cli
2022-04-23 07:29:14 +02:00
# local imports
2022-04-23 11:34:30 +02:00
#from cic_tracker.cache import SyncTimeRedisCache
2022-04-24 13:03:00 +02:00
from cic_tracker.settings import CICTrackerSettings
from cic_tracker.callback import (
pre_callback,
post_callback,
block_callback,
)
2022-04-23 07:29:14 +02:00
logging.STATETRACE = 5
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
2022-04-24 13:03:00 +02:00
2022-04-23 07:29:14 +02:00
script_dir = os.path.realpath(os.path.dirname(__file__))
2022-04-23 11:34:30 +02:00
exec_dir = os.path.realpath(os.getcwd()) #default_config_dir = os.environ.get('CONFINI_DIR', os.path.join(exec_dir, 'config'))
2022-04-23 07:29:14 +02:00
base_config_dir = os.path.join(script_dir, '..', 'data', 'config')
2022-04-24 21:28:55 +02:00
arg_flags = cic_base.cli.argflag_std_read
local_arg_flags = cic_base.cli.argflag_local_sync
argparser = cic_base.cli.ArgumentParser(arg_flags)
2022-04-23 07:29:14 +02:00
argparser.process_local_flags(local_arg_flags)
args = argparser.parse_args()
2022-04-24 23:16:33 +02:00
if args.list_backends:
for v in [
'fs',
'rocksdb',
'redis',
]:
print(v)
sys.exit(0)
2022-04-23 07:29:14 +02:00
# process config
2022-04-24 21:28:55 +02:00
config = cic_base.cli.Config.from_args(args, arg_flags, local_arg_flags, base_config_dir=base_config_dir)
2022-04-23 11:34:30 +02:00
config.add(args.until, '_UNTIL', True)
2022-04-23 07:29:14 +02:00
2022-04-23 11:34:30 +02:00
def main():
2022-04-24 13:03:00 +02:00
settings = CICTrackerSettings()
settings.process(config)
logg.debug('settings:\n' + str(settings))
drv = ChainInterfaceDriver(
2022-04-24 21:28:55 +02:00
settings.get('SYNCER_STORE'),
settings.get('SYNCER_INTERFACE'),
settings.get('SYNCER_OFFSET'),
settings.get('SYNCER_LIMIT'),
2022-04-24 13:03:00 +02:00
pre_callback=pre_callback,
post_callback=post_callback,
block_callback=block_callback,
)
2022-04-23 11:34:30 +02:00
i = 0
try:
2022-04-24 13:03:00 +02:00
r = drv.run(settings.get('RPC'))
2022-04-23 11:34:30 +02:00
except SyncDone as e:
sys.stderr.write("sync {} done at block {}\n".format(drv, e))
2022-04-23 07:29:14 +02:00
if __name__ == '__main__':
main()