2018-12-12 18:54:38 +01:00
|
|
|
import logging
|
|
|
|
import traceback
|
|
|
|
import argparse
|
2019-12-31 22:33:08 +01:00
|
|
|
from lbry.wallet.server.env import Env
|
2022-01-06 18:47:12 +01:00
|
|
|
from lbry.wallet.server.block_processor import BlockProcessor
|
|
|
|
from lbry.wallet.server.chain_reader import BlockchainReaderServer
|
2022-01-21 18:33:33 +01:00
|
|
|
from lbry.wallet.server.db.elasticsearch.sync import ElasticWriter
|
2018-12-12 18:54:38 +01:00
|
|
|
|
|
|
|
|
2022-01-21 18:33:33 +01:00
|
|
|
def get_args_and_setup_logging(name):
|
2018-12-12 18:54:38 +01:00
|
|
|
parser = argparse.ArgumentParser(
|
2022-01-21 18:33:33 +01:00
|
|
|
prog=name
|
2018-12-12 18:54:38 +01:00
|
|
|
)
|
2021-10-20 00:16:36 +02:00
|
|
|
Env.contribute_to_arg_parser(parser)
|
2018-12-12 18:54:38 +01:00
|
|
|
args = parser.parse_args()
|
2021-04-28 22:46:24 +02:00
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
|
2021-03-29 19:16:49 +02:00
|
|
|
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
|
|
|
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
|
2022-01-21 18:33:33 +01:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def run_writer_forever():
|
|
|
|
args = get_args_and_setup_logging('lbry-hub-writer')
|
|
|
|
try:
|
|
|
|
block_processor = BlockProcessor(Env.from_arg_parser(args))
|
|
|
|
block_processor.run()
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
logging.critical('block processor terminated abnormally')
|
|
|
|
else:
|
|
|
|
logging.info('block processor terminated normally')
|
|
|
|
|
|
|
|
|
|
|
|
def run_server_forever():
|
|
|
|
args = get_args_and_setup_logging('lbry-hub-server')
|
|
|
|
|
|
|
|
try:
|
|
|
|
server = BlockchainReaderServer(Env.from_arg_parser(args))
|
|
|
|
server.run()
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
logging.critical('server terminated abnormally')
|
|
|
|
else:
|
|
|
|
logging.info('server terminated normally')
|
|
|
|
|
2022-01-06 18:47:12 +01:00
|
|
|
|
2022-01-21 18:33:33 +01:00
|
|
|
def run_es_sync_forever():
|
|
|
|
args = get_args_and_setup_logging('lbry-hub-elastic-sync')
|
|
|
|
try:
|
|
|
|
server = ElasticWriter(Env.from_arg_parser(args))
|
|
|
|
server.run()
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
logging.critical('es writer terminated abnormally')
|
2018-12-12 18:54:38 +01:00
|
|
|
else:
|
2022-01-21 18:33:33 +01:00
|
|
|
logging.info('es writer terminated normally')
|