non-blocking version check

this fixes a bug where if github is down the app will fail to start.

-check for new version every 30 min instead of every 12 hours

-check connection problems every 30 seconds instead of every second
This commit is contained in:
Jack Robison 2017-02-02 10:18:09 -05:00
parent 41d937d1b4
commit f737b3aaf7

View file

@ -9,6 +9,7 @@ import requests
import urllib
import simplejson as json
import textwrap
from requests import exceptions as requests_exceptions
from decimal import Decimal
from twisted.web import server
@ -128,38 +129,34 @@ class CheckRemoteVersions(object):
self.daemon = daemon
def __call__(self):
d = self._get_lbrynet_version()
d = threads.deferToThread(self._get_lbrynet_version)
d.addErrback(self._trap_and_log_error, 'lbrynet')
d.addCallback(lambda _: self._get_lbryum_version())
d.addErrback(self._trap_and_log_error, 'lbryum')
d.addErrback(log.fail(), 'Failure checking versions on github')
def _trap_and_log_error(self, err, module_checked):
# KeyError is thrown by get_version_from_github
# It'd be better to catch the error before trying to parse the response
err.trap(requests_exceptions.RequestException, KeyError)
if err.check(requests_exceptions.RequestException, KeyError):
log.warning("Failed to check latest %s version from github", module_checked)
def _get_lbryum_version(self):
try:
version = get_lbryum_version_from_github()
self.daemon.git_lbryum_version = get_lbryum_version_from_github()
log.info(
"remote lbryum %s > local lbryum %s = %s",
version, lbryum_version,
utils.version_is_greater_than(version, lbryum_version)
self.daemon.git_lbryum_version, lbryum_version,
utils.version_is_greater_than(self.daemon.git_lbryum_version, lbryum_version)
)
self.daemon.git_lbryum_version = version
return defer.succeed(None)
except Exception:
log.info("Failed to get lbryum version from git")
self.daemon.git_lbryum_version = None
return defer.fail(None)
def _get_lbrynet_version(self):
try:
version = get_lbrynet_version_from_github()
self.daemon.git_lbrynet_version = get_lbrynet_version_from_github()
log.info(
"remote lbrynet %s > local lbrynet %s = %s",
version, lbrynet_version,
utils.version_is_greater_than(version, lbrynet_version)
self.daemon.git_lbrynet_version, lbrynet_version,
utils.version_is_greater_than(self.daemon.git_lbrynet_version, lbryum_version)
)
self.daemon.git_lbrynet_version = version
return defer.succeed(None)
except Exception:
log.info("Failed to get lbrynet version from git")
self.daemon.git_lbrynet_version = None
return defer.fail(None)
class AlwaysSend(object):
@ -304,8 +301,8 @@ class Daemon(AuthJSONRPCServer):
log.info("Starting lbrynet-daemon")
self.looping_call_manager.start(Checker.INTERNET_CONNECTION, 3600)
self.looping_call_manager.start(Checker.VERSION, 3600 * 12)
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 1)
self.looping_call_manager.start(Checker.VERSION, 1800)
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30)
self.exchange_rate_manager.start()
if conf.settings['host_ui']:
@ -1174,12 +1171,12 @@ class Daemon(AuthJSONRPCServer):
try:
lbrynet_update_available = utils.version_is_greater_than(
self.git_lbrynet_version, lbrynet_version)
except AttributeError:
except TypeError:
lbrynet_update_available = False
try:
lbryum_update_available = utils.version_is_greater_than(
self.git_lbryum_version, lbryum_version)
except AttributeError:
except TypeError:
lbryum_update_available = False
msg = {
'platform': platform_info['platform'],