Merge branch 'lash/health-util' into 'master'
K8s health utilities for cic containers See merge request grassrootseconomics/cic-internal-integration!108
This commit is contained in:
7
apps/cic-eth/cic_eth/k8s/db.py
Normal file
7
apps/cic-eth/cic_eth/k8s/db.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
|
||||
def health(*args, **kwargs):
|
||||
session = SessionBase.create_session()
|
||||
session.execute('SELECT count(*) from alembic_version')
|
||||
session.close()
|
||||
return True
|
||||
@@ -15,6 +15,7 @@ from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.connection import EthUnixSignerConnection
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainqueue.db.models.otx import Otx
|
||||
import liveness.linux
|
||||
|
||||
# local imports
|
||||
from cic_eth.eth import (
|
||||
@@ -52,6 +53,7 @@ from cic_eth.registry import (
|
||||
connect_token_registry,
|
||||
)
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
@@ -90,14 +92,15 @@ config.censor('PASSWORD', 'DATABASE')
|
||||
config.censor('PASSWORD', 'SSL')
|
||||
logg.debug('config loaded from {}:\n{}'.format(args.c, config))
|
||||
|
||||
health_modules = config.get('CIC_HEALTH_MODULES', [])
|
||||
if len(health_modules) != 0:
|
||||
health_modules = health_modules.split(',')
|
||||
logg.debug('health mods {}'.format(health_modules))
|
||||
|
||||
# connect to database
|
||||
dsn = dsn_from_config(config)
|
||||
SessionBase.connect(dsn, pool_size=int(config.get('DATABASE_POOL_SIZE')), debug=config.true('DATABASE_DEBUG'))
|
||||
|
||||
# verify database connection with minimal sanity query
|
||||
session = SessionBase.create_session()
|
||||
session.execute('select version_num from alembic_version')
|
||||
session.close()
|
||||
|
||||
# set up celery
|
||||
current_app = celery.Celery(__name__)
|
||||
@@ -139,6 +142,7 @@ RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 's
|
||||
|
||||
Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS')
|
||||
|
||||
liveness.linux.load(health_modules)
|
||||
|
||||
def main():
|
||||
argv = ['worker']
|
||||
@@ -173,8 +177,10 @@ def main():
|
||||
logg.info('using trusted address {}'.format(address))
|
||||
connect_declarator(rpc, chain_spec, trusted_addresses)
|
||||
connect_token_registry(rpc, chain_spec)
|
||||
|
||||
|
||||
liveness.linux.set()
|
||||
current_app.worker_main(argv)
|
||||
liveness.linux.reset()
|
||||
|
||||
|
||||
@celery.signals.eventlet_pool_postshutdown.connect
|
||||
|
||||
Reference in New Issue
Block a user