switch startup sequence to use inlineCallbacks
This cleans up the process, makes it more readable, and better surfaces errors.
This commit is contained in:
parent
fc24d9b5aa
commit
2c7fc3fb46
3 changed files with 30 additions and 37 deletions
|
@ -290,13 +290,10 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.lbry_file_metadata_manager = None
|
||||
self.lbry_file_manager = None
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def setup(self):
|
||||
self._modify_loggly_formatter()
|
||||
|
||||
def _log_starting_vals():
|
||||
log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
|
||||
return defer.succeed(None)
|
||||
|
||||
def _announce_startup():
|
||||
def _wait_for_credits():
|
||||
if float(self.session.wallet.wallet_balance) == 0.0:
|
||||
|
@ -330,26 +327,23 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.looping_call_manager.start(Checker.CONNECTION_PROBLEM, 1)
|
||||
self.exchange_rate_manager.start()
|
||||
|
||||
d = defer.Deferred()
|
||||
if conf.settings.host_ui:
|
||||
self.lbry_ui_manager.update_checker.start(1800, now=False)
|
||||
d.addCallback(lambda _: self.lbry_ui_manager.setup())
|
||||
d.addCallback(lambda _: self._initial_setup())
|
||||
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
|
||||
d.addCallback(lambda _: self._check_db_migration())
|
||||
d.addCallback(lambda _: self._load_caches())
|
||||
d.addCallback(lambda _: self._set_events())
|
||||
d.addCallback(lambda _: self._get_session())
|
||||
d.addCallback(lambda _: self._get_analytics())
|
||||
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
|
||||
d.addCallback(lambda _: self._setup_stream_identifier())
|
||||
d.addCallback(lambda _: self._setup_lbry_file_manager())
|
||||
d.addCallback(lambda _: self._setup_query_handlers())
|
||||
d.addCallback(lambda _: self._setup_server())
|
||||
d.addCallback(lambda _: _log_starting_vals())
|
||||
d.addCallback(lambda _: _announce_startup())
|
||||
d.callback(None)
|
||||
return d
|
||||
yield self.lbry_ui_manager.setup()
|
||||
yield self._initial_setup()
|
||||
yield threads.deferToThread(self._setup_data_directory)
|
||||
yield self._check_db_migration()
|
||||
yield self._load_caches()
|
||||
yield self._set_events()
|
||||
yield self._get_session()
|
||||
yield self._get_analytics()
|
||||
yield add_lbry_file_to_sd_identifier(self.sd_identifier)
|
||||
yield self._setup_stream_identifier()
|
||||
yield self._setup_lbry_file_manager()
|
||||
yield self._setup_query_handlers()
|
||||
yield self._setup_server()
|
||||
log.info("Starting balance: " + str(self.session.wallet.wallet_balance))
|
||||
yield _announce_startup()
|
||||
|
||||
def _get_platform(self):
|
||||
if self.platform is None:
|
||||
|
@ -756,7 +750,6 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
d.addCallback(create_session)
|
||||
d.addCallback(lambda _: self.session.setup())
|
||||
|
||||
return d
|
||||
|
||||
def _setup_stream_identifier(self):
|
||||
|
|
|
@ -117,11 +117,7 @@ def update_settings_from_args(args):
|
|||
settings.update(to_pass)
|
||||
|
||||
|
||||
def kill(failure, analytics_manager):
|
||||
analytics_manager.send_server_startup_error(failure.getErrorMessage() + " " + str(failure))
|
||||
reactor.callFromThread(reactor.stop)
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def start_server_and_listen(launchui, use_auth, analytics_manager):
|
||||
"""The primary entry point for launching the daemon.
|
||||
|
||||
|
@ -130,12 +126,16 @@ def start_server_and_listen(launchui, use_auth, analytics_manager):
|
|||
use_auth: set to true to enable http authentication
|
||||
analytics_manager: to send analytics
|
||||
"""
|
||||
daemon_server = DaemonServer(analytics_manager)
|
||||
d = daemon_server.start(use_auth)
|
||||
if launchui:
|
||||
d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
|
||||
d.addCallback(lambda _: analytics_manager.send_server_startup_success())
|
||||
d.addErrback(log.fail(kill, analytics_manager), 'Failed to startup')
|
||||
try:
|
||||
daemon_server = DaemonServer(analytics_manager)
|
||||
yield daemon_server.start(use_auth)
|
||||
if launchui:
|
||||
yield webbrowser.open(settings.UI_ADDRESS)
|
||||
yield analytics_manager.send_server_startup_success()
|
||||
except Exception as e:
|
||||
log.exception('Failed to startup')
|
||||
analytics_manager.send_server_startup_error(str(e))
|
||||
reactor.callFromThread(reactor.stop)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -41,10 +41,10 @@ class DaemonServer(object):
|
|||
|
||||
return defer.succeed(True)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def start(self, use_auth):
|
||||
d = self._setup_server(use_auth)
|
||||
d.addCallback(lambda _: self._api.setup())
|
||||
return d
|
||||
yield self._setup_server(use_auth)
|
||||
yield self._api.setup()
|
||||
|
||||
|
||||
def get_site_base(use_auth, root):
|
||||
|
|
Loading…
Reference in a new issue