set daemon attribute for each component as they start

This commit is contained in:
Jack Robison 2018-07-20 14:48:31 -04:00
parent 55d3bb0ec3
commit defe9506bb
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 22 additions and 10 deletions

View file

@ -42,6 +42,7 @@ class Component(object):
def stop(self):
raise NotImplementedError()
@property
def component(self):
raise NotImplementedError()

View file

@ -88,7 +88,7 @@ class ComponentManager(object):
def _setup(component):
if component.component_name in callbacks:
d = component._setup()
d.addCallback(callbacks[component.component_name])
d.addCallback(callbacks[component.component_name], component)
return d
return component._setup()

View file

@ -153,6 +153,16 @@ class Daemon(AuthJSONRPCServer):
LBRYnet daemon, a jsonrpc interface to lbry functions
"""
component_attributes = {
EXCHANGE_RATE_MANAGER_COMPONENT: "exchange_rate_manager",
DATABASE_COMPONENT: "storage",
SESSION_COMPONENT: "session",
WALLET_COMPONENT: "wallet",
DHT_COMPONENT: "dht_node",
STREAM_IDENTIFIER_COMPONENT: "sd_identifier",
FILE_MANAGER_COMPONENT: "file_manager",
}
def __init__(self, analytics_manager, component_manager=None):
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
self.download_directory = conf.settings['download_directory']
@ -208,15 +218,16 @@ class Daemon(AuthJSONRPCServer):
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30)
yield self._initial_setup()
yield self.component_manager.setup()
self.exchange_rate_manager = self.component_manager.get_component(EXCHANGE_RATE_MANAGER_COMPONENT)
self.storage = self.component_manager.get_component(DATABASE_COMPONENT)
self.session = self.component_manager.get_component(SESSION_COMPONENT)
self.wallet = self.component_manager.get_component(WALLET_COMPONENT)
self.dht_node = self.component_manager.get_component(DHT_COMPONENT)
yield self._start_analytics()
self.sd_identifier = self.component_manager.get_component(STREAM_IDENTIFIER_COMPONENT)
self.file_manager = self.component_manager.get_component(FILE_MANAGER_COMPONENT)
def update_attr(component_setup_result, component):
setattr(self, self.component_attributes[component.component_name], component.component)
setup_callbacks = {
component_name: update_attr for component_name in self.component_attributes.keys()
}
yield self.component_manager.setup(**setup_callbacks)
log.info("Starting balance: " + str(self.wallet.get_balance()))
self.announced_startup = True
log.info("Started lbrynet-daemon")

View file

@ -164,7 +164,7 @@ class AuthorizedBase(object):
result = yield fn(*args, **kwargs)
defer.returnValue(result)
else:
raise ComponentsNotStarted("Not all required components are set up:", components)
raise ComponentsNotStarted("Not all required components are set up: %s" % json.dumps(components))
return _inner
return _wrap