forked from LBRYCommunity/lbry-sdk
adjust the _online variable to be set on the errback, so any exception will set _online to False
This commit is contained in:
parent
7e7931fbf1
commit
020a2e0e89
1 changed files with 5 additions and 7 deletions
|
@ -56,11 +56,7 @@ class MarketFeed(object):
|
||||||
|
|
||||||
def _make_request(self):
|
def _make_request(self):
|
||||||
r = requests.get(self.url, self.params, timeout=self.REQUESTS_TIMEOUT)
|
r = requests.get(self.url, self.params, timeout=self.REQUESTS_TIMEOUT)
|
||||||
if r.status_code == 200:
|
|
||||||
self._online = True
|
|
||||||
return r.text
|
return r.text
|
||||||
self._online = False
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def _handle_response(self, response):
|
def _handle_response(self, response):
|
||||||
return NotImplementedError
|
return NotImplementedError
|
||||||
|
@ -72,18 +68,20 @@ class MarketFeed(object):
|
||||||
def _save_price(self, price):
|
def _save_price(self, price):
|
||||||
log.debug("Saving price update %f for %s from %s" % (price, self.market, self.name))
|
log.debug("Saving price update %f for %s from %s" % (price, self.market, self.name))
|
||||||
self.rate = ExchangeRate(self.market, price, int(time.time()))
|
self.rate = ExchangeRate(self.market, price, int(time.time()))
|
||||||
|
self._online = True
|
||||||
|
|
||||||
def _log_error(self, err):
|
def _on_error(self, err):
|
||||||
log.warning(
|
log.warning(
|
||||||
"There was a problem updating %s exchange rate information from %s: %s",
|
"There was a problem updating %s exchange rate information from %s: %s",
|
||||||
self.market, self.name, err)
|
self.market, self.name, err)
|
||||||
|
self._online = False
|
||||||
|
|
||||||
def _update_price(self):
|
def _update_price(self):
|
||||||
d = threads.deferToThread(self._make_request)
|
d = threads.deferToThread(self._make_request)
|
||||||
d.addCallback(self._handle_response)
|
d.addCallback(self._handle_response)
|
||||||
d.addCallback(self._subtract_fee)
|
d.addCallback(self._subtract_fee)
|
||||||
d.addCallback(self._save_price)
|
d.addCallback(self._save_price)
|
||||||
d.addErrback(self._log_error)
|
d.addErrback(self._on_error)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
Loading…
Reference in a new issue