Add base setup for sql backend

This commit is contained in:
nolash 2021-06-03 13:54:49 +02:00
parent 2400084251
commit 90d091edfd
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 15 additions and 8 deletions

View File

@ -22,6 +22,9 @@ class SQLBackend(Backend):
:param object_id: Unique id for the syncer session. :param object_id: Unique id for the syncer session.
:type object_id: number :type object_id: number
""" """
base = None
def __init__(self, chain_spec, object_id): def __init__(self, chain_spec, object_id):
super(SQLBackend, self).__init__() super(SQLBackend, self).__init__()
self.db_session = None self.db_session = None
@ -33,6 +36,13 @@ class SQLBackend(Backend):
self.disconnect() self.disconnect()
@classmethod
def setup(cls, dsn, debug=False, *args, **kwargs):
if cls.base == None:
cls.base = SessionBase
cls.base.connect(dsn, debug=debug, pool_size=kwargs.get('pool_size', 0))
def connect(self): def connect(self):
"""Loads the state of the syncer session with the given id. """Loads the state of the syncer session with the given id.
""" """
@ -264,7 +274,6 @@ class SQLBackend(Backend):
:returns: "Live" syncer object :returns: "Live" syncer object
:rtype: cic_eth.db.models.BlockchainSync :rtype: cic_eth.db.models.BlockchainSync
""" """
object_id = None
session = SessionBase.create_session() session = SessionBase.create_session()
o = BlockchainSync(str(chain_spec), block_height, 0, None) o = BlockchainSync(str(chain_spec), block_height, 0, None)

View File

@ -1,10 +1,10 @@
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
def chainsyncer_upgrade(major, minor, patch): def chainsyncer_upgrade(major=0, minor=0, patch=1):
r0_0_1_u() r0_0_1_u()
def chainsyncer_downgrade(major, minor, patch): def chainsyncer_downgrade(major=0, minor=0, patch=1):
r0_0_1_d() r0_0_1_d()
def r0_0_1_u(): def r0_0_1_u():

View File

@ -42,7 +42,6 @@ argparser = argparse.ArgumentParser(description='daemon that monitors transactio
argparser.add_argument('-p', '--provider', dest='p', type=str, help='chain rpc provider address') argparser.add_argument('-p', '--provider', dest='p', type=str, help='chain rpc provider address')
argparser.add_argument('-c', type=str, default=config_dir, help='config root to use') argparser.add_argument('-c', type=str, default=config_dir, help='config root to use')
argparser.add_argument('-i', '--chain-spec', type=str, dest='i', help='chain spec') argparser.add_argument('-i', '--chain-spec', type=str, dest='i', help='chain spec')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, help='Directory containing bytecode and abi')
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
argparser.add_argument('--offset', type=int, help='block number to start sync') argparser.add_argument('--offset', type=int, help='block number to start sync')
argparser.add_argument('-q', type=str, default='cic-eth', help='celery queue to submit transaction tasks to') argparser.add_argument('-q', type=str, default='cic-eth', help='celery queue to submit transaction tasks to')
@ -56,7 +55,6 @@ elif args.vv == True:
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
config_dir = os.path.join(args.c) config_dir = os.path.join(args.c)
os.makedirs(config_dir, 0o777, True)
config = confini.Config(config_dir, args.env_prefix) config = confini.Config(config_dir, args.env_prefix)
config.process() config.process()
# override args # override args

View File

@ -1,4 +1,4 @@
confini~=0.3.6rc3 confini~=0.3.6rc3
semver==2.13.0 semver==2.13.0
hexathon~=0.0.1a7 hexathon~=0.0.1a7
chainlib~=0.0.2a15 chainlib~=0.0.3rc2

View File

@ -1,10 +1,10 @@
[metadata] [metadata]
name = chainsyncer name = chainsyncer
version = 0.0.2a3 version = 0.0.2a5
description = Generic blockchain syncer driver description = Generic blockchain syncer driver
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no
url = https://gitlab.com/nolash/chainsyncer url = https://gitlab.com/chaintools/chainsyncer
keywords = keywords =
cryptocurrency cryptocurrency
classifiers = classifiers =