Merge pull request #408 from lbryio/non-blocking-update-check
non-blocking version check
This commit is contained in:
commit
6f0581104a
1 changed files with 29 additions and 32 deletions
|
@ -9,6 +9,7 @@ import requests
|
||||||
import urllib
|
import urllib
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from requests import exceptions as requests_exceptions
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from twisted.web import server
|
from twisted.web import server
|
||||||
|
@ -128,38 +129,34 @@ class CheckRemoteVersions(object):
|
||||||
self.daemon = daemon
|
self.daemon = daemon
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
d = self._get_lbrynet_version()
|
d = threads.deferToThread(self._get_lbrynet_version)
|
||||||
d.addCallback(lambda _: self._get_lbryum_version())
|
d.addErrback(self._trap_and_log_error, 'lbrynet')
|
||||||
|
d.addCallback(lambda _: threads.deferToThread(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):
|
def _get_lbryum_version(self):
|
||||||
try:
|
self.daemon.git_lbryum_version = get_lbryum_version_from_github()
|
||||||
version = get_lbryum_version_from_github()
|
log.info(
|
||||||
log.info(
|
"remote lbryum %s > local lbryum %s = %s",
|
||||||
"remote lbryum %s > local lbryum %s = %s",
|
self.daemon.git_lbryum_version, lbryum_version,
|
||||||
version, lbryum_version,
|
utils.version_is_greater_than(self.daemon.git_lbryum_version, lbryum_version)
|
||||||
utils.version_is_greater_than(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):
|
def _get_lbrynet_version(self):
|
||||||
try:
|
self.daemon.git_lbrynet_version = get_lbrynet_version_from_github()
|
||||||
version = get_lbrynet_version_from_github()
|
log.info(
|
||||||
log.info(
|
"remote lbrynet %s > local lbrynet %s = %s",
|
||||||
"remote lbrynet %s > local lbrynet %s = %s",
|
self.daemon.git_lbrynet_version, lbrynet_version,
|
||||||
version, lbrynet_version,
|
utils.version_is_greater_than(self.daemon.git_lbrynet_version, lbryum_version)
|
||||||
utils.version_is_greater_than(version, lbrynet_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):
|
class AlwaysSend(object):
|
||||||
|
@ -304,8 +301,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
log.info("Starting lbrynet-daemon")
|
log.info("Starting lbrynet-daemon")
|
||||||
|
|
||||||
self.looping_call_manager.start(Checker.INTERNET_CONNECTION, 3600)
|
self.looping_call_manager.start(Checker.INTERNET_CONNECTION, 3600)
|
||||||
self.looping_call_manager.start(Checker.VERSION, 3600 * 12)
|
self.looping_call_manager.start(Checker.VERSION, 1800)
|
||||||
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 1)
|
self.looping_call_manager.start(Checker.CONNECTION_STATUS, 30)
|
||||||
self.exchange_rate_manager.start()
|
self.exchange_rate_manager.start()
|
||||||
|
|
||||||
if conf.settings['host_ui']:
|
if conf.settings['host_ui']:
|
||||||
|
@ -1167,12 +1164,12 @@ class Daemon(AuthJSONRPCServer):
|
||||||
try:
|
try:
|
||||||
lbrynet_update_available = utils.version_is_greater_than(
|
lbrynet_update_available = utils.version_is_greater_than(
|
||||||
self.git_lbrynet_version, lbrynet_version)
|
self.git_lbrynet_version, lbrynet_version)
|
||||||
except AttributeError:
|
except TypeError:
|
||||||
lbrynet_update_available = False
|
lbrynet_update_available = False
|
||||||
try:
|
try:
|
||||||
lbryum_update_available = utils.version_is_greater_than(
|
lbryum_update_available = utils.version_is_greater_than(
|
||||||
self.git_lbryum_version, lbryum_version)
|
self.git_lbryum_version, lbryum_version)
|
||||||
except AttributeError:
|
except TypeError:
|
||||||
lbryum_update_available = False
|
lbryum_update_available = False
|
||||||
msg = {
|
msg = {
|
||||||
'platform': platform_info['platform'],
|
'platform': platform_info['platform'],
|
||||||
|
|
Loading…
Reference in a new issue