Improve data dir generation, improve socket settings handling
This commit is contained in:
parent
e54f03a8f6
commit
800b70680b
@ -28,7 +28,6 @@ class ChaindFsAdapter(ChaindAdapter):
|
||||
|
||||
|
||||
def put(self, signed_tx):
|
||||
#cache_tx = self.deserialize(signed_tx)
|
||||
(s, tx_hash,) = self.store.put(signed_tx, cache_adapter=self.cache_adapter)
|
||||
return tx_hash
|
||||
|
||||
|
@ -2,10 +2,16 @@
|
||||
from .base import ChaindFlag
|
||||
|
||||
def process_flags(argparser, flags):
|
||||
if flags & ChaindFlag.SESSION:
|
||||
if flags & ChaindFlag.SESSION > 0:
|
||||
argparser.add_argument('--session-id', dest='session_id', type=str, help='Session to store state and data under')
|
||||
argparser.add_argument('--runtime-dir', dest='runtime_dir', type=str, help='Directory to store volatile data')
|
||||
argparser.add_argument('--data-dir', dest='data_dir', type=str, help='Directory to store persistent data')
|
||||
|
||||
if flags & ChaindFlag.SOCKET:
|
||||
argparser.add_argument('--socket', type=str, help='Socket path to send transactions to (assumes -s).')
|
||||
if flags & ChaindFlag.SOCKET > 0:
|
||||
argparser.add_argument('--socket-path', dest='socket', type=str, help='UNIX socket path')
|
||||
|
||||
if flags & ChaindFlag.SOCKET_CLIENT > 0:
|
||||
argparser.add_argument('--send-socket', dest='socket_send', action='store_true', help='Send to UNIX socket')
|
||||
|
||||
if flags & ChaindFlag.TOKEN > 0:
|
||||
argparser.add_argument('--token-module', dest='token_module', type=str, help='Python module path to resolve tokens from identifiers')
|
||||
|
@ -4,7 +4,10 @@ import enum
|
||||
|
||||
class ChaindFlag(enum.IntEnum):
|
||||
SESSION = 1
|
||||
DISPATCH = 512
|
||||
SOCKET = 4096
|
||||
DISPATCH = 2
|
||||
SOCKET = 16
|
||||
SOCKET_CLIENT = 32
|
||||
TOKEN = 256
|
||||
|
||||
argflag_local_base = ChaindFlag.SESSION
|
||||
argflag_local_socket_client = ChaindFlag.SESSION | ChaindFlag.SOCKET | ChaindFlag.SOCKET_CLIENT
|
||||
|
@ -3,15 +3,21 @@ from chaind.cli import ChaindFlag
|
||||
|
||||
|
||||
def process_config(config, args, flags):
|
||||
args_override = {}
|
||||
if flags & ChaindFlag.SESSION:
|
||||
args_override['SESSION_ID'] = getattr(args, 'session_id')
|
||||
args_override['SESSION_RUNTIME_DIR'] = getattr(args, 'runtime_dir')
|
||||
args_override['SESSION_DATA_DIR'] = getattr(args, 'data_dir')
|
||||
args_override = {}
|
||||
if flags & ChaindFlag.SESSION:
|
||||
args_override['SESSION_ID'] = getattr(args, 'session_id')
|
||||
args_override['SESSION_RUNTIME_DIR'] = getattr(args, 'runtime_dir')
|
||||
args_override['SESSION_DATA_DIR'] = getattr(args, 'data_dir')
|
||||
|
||||
if flags & ChaindFlag.SOCKET:
|
||||
args_override['SESSION_SOCKET_PATH'] = getattr(args, 'socket')
|
||||
if flags & ChaindFlag.SOCKET:
|
||||
args_override['SESSION_SOCKET_PATH'] = getattr(args, 'socket')
|
||||
|
||||
config.dict_override(args_override, 'local cli args')
|
||||
if flags & ChaindFlag.TOKEN:
|
||||
args_override['TOKEN_MODULE'] = getattr(args, 'token_module')
|
||||
|
||||
return config
|
||||
config.dict_override(args_override, 'local cli args')
|
||||
|
||||
if flags & ChaindFlag.SOCKET_CLIENT:
|
||||
config.add(getattr(args, 'socket_send'), '_SOCKET_SEND', False)
|
||||
|
||||
return config
|
||||
|
@ -3,3 +3,4 @@ socket_path =
|
||||
runtime_dir =
|
||||
id =
|
||||
data_dir =
|
||||
|
||||
|
@ -21,6 +21,7 @@ class StateFilter(SyncFilter):
|
||||
except NotLocalTxError:
|
||||
logg.debug('skipping not local transaction {}'.format(tx.hash))
|
||||
return False
|
||||
|
||||
if tx.status == TxStatus.SUCCESS:
|
||||
self.adapter.succeed(block, tx)
|
||||
else:
|
||||
|
@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
# external imports
|
||||
from chainlib.chain import ChainSpec
|
||||
@ -20,9 +21,8 @@ class ChaindSettings(ChainsyncerSettings):
|
||||
|
||||
def process_common(self, config):
|
||||
self.o['CHAIN_SPEC'] = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||
self.o['SOCKET_PATH'] = config.get('SESSION_SOCKET_PATH')
|
||||
|
||||
|
||||
|
||||
def process_session(self, config):
|
||||
session_id = config.get('SESSION_ID')
|
||||
|
||||
@ -55,7 +55,7 @@ class ChaindSettings(ChainsyncerSettings):
|
||||
fp = os.path.join(data_engine_dir, 'default')
|
||||
os.symlink(session_dir, fp)
|
||||
|
||||
data_dir = os.path.join(session_dir, 'sync')
|
||||
data_dir = os.path.join(session_dir, config.get('CHAIND_COMPONENT'))
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
|
||||
# create volatile dir
|
||||
@ -63,10 +63,11 @@ class ChaindSettings(ChainsyncerSettings):
|
||||
runtime_dir = config.get('SESSION_RUNTIME_DIR')
|
||||
if runtime_dir == None:
|
||||
runtime_dir = os.path.join('/run', 'user', str(uid), 'chaind')
|
||||
runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id, 'sync')
|
||||
runtime_dir = os.path.join(runtime_dir, config.get('CHAIND_ENGINE'), session_id, config.get('CHAIND_COMPONENT'))
|
||||
os.makedirs(runtime_dir, exist_ok=True)
|
||||
|
||||
self.o['SESSION_RUNTIME_DIR'] = runtime_dir
|
||||
self.o['SESSION_DIR'] = session_dir
|
||||
self.o['SESSION_DATA_DIR'] = data_dir
|
||||
self.o['SESSION_ID'] = session_id
|
||||
|
||||
@ -101,6 +102,10 @@ class ChaindSettings(ChainsyncerSettings):
|
||||
self.process_dispatch(config)
|
||||
|
||||
|
||||
def dir_for(self, k):
|
||||
return os.path.join(self.o['SESSION_DIR'], k)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
ks = list(self.o.keys())
|
||||
ks.sort()
|
||||
|
Loading…
Reference in New Issue
Block a user