is_lagging indicator and internet connection check

-adds is_lagging indicator as a key from daemon_status, which is set to
True during a phase of the startup sequence, presently only during
loading_wallet if catching up with the blockchain takes longer than a
minute.

-checks if connected to internet before trying to start
This commit is contained in:
Jack 2016-04-14 00:29:40 -04:00
parent 6b9f1d519e
commit 47d897b48d
3 changed files with 42 additions and 21 deletions

View file

@ -70,6 +70,8 @@ class LBRYWallet(object):
self.max_expected_payment_time = datetime.timedelta(minutes=3) self.max_expected_payment_time = datetime.timedelta(minutes=3)
self.stopped = True self.stopped = True
self.is_lagging = None
self.manage_running = False self.manage_running = False
self._manage_count = 0 self._manage_count = 0
self._balance_refresh_time = 3 self._balance_refresh_time = 3
@ -996,15 +998,17 @@ class LBRYumWallet(LBRYWallet):
self._catch_up_check = None self._catch_up_check = None
blockchain_caught_d.callback(True) blockchain_caught_d.callback(True)
elif remote_height != 0: elif remote_height != 0:
self.blocks_behind_alert = remote_height - local_height
if self.blocks_behind_alert > self.max_behind:
self.max_behind = self.blocks_behind_alert
self.catchup_progress = int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))
if self._caught_up_counter == 0: if self._caught_up_counter == 0:
alert.info('Catching up to the blockchain...showing blocks left...') alert.info('Catching up to the blockchain...showing blocks left...')
if self._caught_up_counter % 30 == 0: if self._caught_up_counter % 30 == 0:
self.blocks_behind_alert = remote_height - local_height
if self.blocks_behind_alert > self.max_behind:
self.max_behind = self.blocks_behind_alert
self.catchup_progress = int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))
alert.info('%d...', (remote_height - local_height)) alert.info('%d...', (remote_height - local_height))
alert.info("Catching up: " + str(int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))) + "%") alert.info("Catching up: " + str(self.catchup_progress) + "%")
if self._caught_up_counter >= 600:
self.is_lagging = True
self._caught_up_counter += 1 self._caught_up_counter += 1

View file

@ -928,10 +928,12 @@ class LBRYDaemon(jsonrpc.JSONRPC):
if status_code is 'loading_wallet', also contains key 'progress': blockchain catchup progress if status_code is 'loading_wallet', also contains key 'progress': blockchain catchup progress
""" """
r = {'code': self.startup_status[0], 'message': self.startup_status[1], 'progress': None} r = {'code': self.startup_status[0], 'message': self.startup_status[1], 'progress': None, 'is_lagging': None}
if self.startup_status[0] == 'loading_wallet': if self.startup_status[0] == 'loading_wallet':
r['message'] = r['message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind") r['message'] = r['message'] % (str(self.session.wallet.blocks_behind_alert) + " blocks behind")
r['progress'] = self.session.wallet.catchup_progress r['progress'] = self.session.wallet.catchup_progress
r['is_lagging'] = self.session.wallet.is_lagging
log.info("[" + str(datetime.now()) + "] daemon status: " + str(r)) log.info("[" + str(datetime.now()) + "] daemon status: " + str(r))
return self._render_response(r, OK_CODE) return self._render_response(r, OK_CODE)

View file

@ -6,6 +6,8 @@ import os
import shutil import shutil
import webbrowser import webbrowser
import sys import sys
import socket
from StringIO import StringIO from StringIO import StringIO
from zipfile import ZipFile from zipfile import ZipFile
@ -34,6 +36,16 @@ handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=262144, ba
log.addHandler(handler) log.addHandler(handler)
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
REMOTE_SERVER = "www.google.com"
def test_internet_connection():
try:
host = socket.gethostbyname(REMOTE_SERVER)
s = socket.create_connection((host, 80), 2)
return True
except:
return False
def stop(): def stop():
def _disp_shutdown(): def _disp_shutdown():
@ -104,6 +116,10 @@ def start():
version_dir = os.path.join(data_dir, "ui_version_history") version_dir = os.path.join(data_dir, "ui_version_history")
git_version = subprocess.check_output(GIT_CMD_STRING, shell=True) git_version = subprocess.check_output(GIT_CMD_STRING, shell=True)
if not git_version:
log.info("You should have been notified to install xcode command line tools, once it's installed you can start LBRY")
sys.exit(0)
ui_version_info = git_version ui_version_info = git_version
if not os.path.isdir(data_dir): if not os.path.isdir(data_dir):
@ -113,15 +129,11 @@ def start():
os.mkdir(version_dir) os.mkdir(version_dir)
if not os.path.isfile(os.path.join(version_dir, git_version)): if not os.path.isfile(os.path.join(version_dir, git_version)):
try: f = open(os.path.join(version_dir, git_version), "w")
f = open(os.path.join(version_dir, git_version), "w") version_message = "[" + str(datetime.now()) + "] Updating UI --> " + git_version
version_message = "[" + str(datetime.now()) + "] Updating UI --> " + git_version f.write(version_message)
f.write(version_message) f.close()
f.close() log.info(version_message)
log.info(version_message)
except:
log.info("You should have been notified to install xcode command line tools, once it's installed you can start LBRY")
sys.exit(0)
if os.path.isdir(os.path.join(data_dir, "lbry-web-ui")): if os.path.isdir(os.path.join(data_dir, "lbry-web-ui")):
shutil.rmtree(os.path.join(data_dir, "lbry-web-ui")) shutil.rmtree(os.path.join(data_dir, "lbry-web-ui"))
@ -149,9 +161,12 @@ def start():
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE) reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
return daemon.setup() return daemon.setup()
d = getui(args.ui) if test_internet_connection():
d.addCallback(lambda r: setupserver(r[0], r[1])) d = getui(args.ui)
d.addCallback(lambda r: setupapi(r[0], args.wallet, r[1])) d.addCallback(lambda r: setupserver(r[0], r[1]))
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS)) d.addCallback(lambda r: setupapi(r[0], args.wallet, r[1]))
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
reactor.run() reactor.run()
else:
log.info("Not connected to internet, unable to start")
return