mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
set daemon attribute for each component as they start
This commit is contained in:
parent
55d3bb0ec3
commit
defe9506bb
4 changed files with 22 additions and 10 deletions
|
@ -42,6 +42,7 @@ class Component(object):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@property
|
||||||
def component(self):
|
def component(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ class ComponentManager(object):
|
||||||
def _setup(component):
|
def _setup(component):
|
||||||
if component.component_name in callbacks:
|
if component.component_name in callbacks:
|
||||||
d = component._setup()
|
d = component._setup()
|
||||||
d.addCallback(callbacks[component.component_name])
|
d.addCallback(callbacks[component.component_name], component)
|
||||||
return d
|
return d
|
||||||
return component._setup()
|
return component._setup()
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,16 @@ class Daemon(AuthJSONRPCServer):
|
||||||
LBRYnet daemon, a jsonrpc interface to lbry functions
|
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):
|
def __init__(self, analytics_manager, component_manager=None):
|
||||||
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
|
AuthJSONRPCServer.__init__(self, conf.settings['use_auth_http'])
|
||||||
self.download_directory = conf.settings['download_directory']
|
self.download_directory = conf.settings['download_directory']
|
||||||
|
@ -208,15 +218,16 @@ class Daemon(AuthJSONRPCServer):
|
||||||
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30)
|
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30)
|
||||||
|
|
||||||
yield self._initial_setup()
|
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()
|
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()))
|
log.info("Starting balance: " + str(self.wallet.get_balance()))
|
||||||
self.announced_startup = True
|
self.announced_startup = True
|
||||||
log.info("Started lbrynet-daemon")
|
log.info("Started lbrynet-daemon")
|
||||||
|
|
|
@ -164,7 +164,7 @@ class AuthorizedBase(object):
|
||||||
result = yield fn(*args, **kwargs)
|
result = yield fn(*args, **kwargs)
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
else:
|
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 _inner
|
||||||
return _wrap
|
return _wrap
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue