Merge pull request #195 from R4stl1n/221

Tolerate random 221 errors from API servers
This commit is contained in:
Adarnof 2016-01-24 16:49:16 -05:00
commit cd87d90088
3 changed files with 43 additions and 12 deletions

View File

@ -321,25 +321,57 @@ def run_api_refresh():
still_valid = True
if authserviceinfo.is_blue:
if settings.BLUE_API_ACCOUNT:
if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
type = EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key)
if type == None:
api_key_pair.error_count += 1
api_key_pair.save()
logger.info("API key %s incurred an error checking if type account. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
still_valid = None
elif type == False:
logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
still_valid = False
if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
full = EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
if full == None:
api_key_pair.error_count += 1
api_key_pair.save()
logger.info("API key %s incurred an error checking if meets mask requirements. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
still_valid = None
elif full == False:
logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
still_valid = False
else:
if settings.MEMBER_API_ACCOUNT:
if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
type = EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key)
if type == None:
api_key_pair.error_count += 1
api_key_pair.save()
logger.info("API key %s incurred an error checking if type account. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
still_valid = None
elif type == False:
logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
still_valid = False
if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
full = EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key)
if full == None:
api_key_pair.error_count += 1
api_key_pair.save()
logger.info("API key %s incurred an error checking if meets mask requirements. Error count is now %s" % (api_key_pair.api_id, api_key_pair.error_count))
still_valid = None
elif full == False:
logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
still_valid = False
if still_valid is not True:
if still_valid == None:
if api_key_pair.error_count >= 3:
logger.info("API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id)
still_valid = False
if still_valid == False:
logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
else:
if api_key_pair.error_count != 0:
logger.info("Clearing error count for api %s as it passed validation" % api_key_pair.api_id)
api_key_pair.error_count = 0
api_key_pair.save()
logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
# Update characters
characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,

View File

@ -21,6 +21,7 @@ class EveApiKeyPair(models.Model):
api_id = models.CharField(max_length=254)
api_key = models.CharField(max_length=254)
user = models.ForeignKey(User)
error_count = models.PositiveIntegerField(default=0)
def __str__(self):
return self.user.username + " - ApiKeyPair"
@ -47,4 +48,4 @@ class EveCorporationInfo(models.Model):
alliance = models.ForeignKey(EveAllianceInfo, blank=True, null=True)
def __str__(self):
return self.corporation_name
return self.corporation_name

View File

@ -83,8 +83,7 @@ class EveApiManager():
except evelink.api.APIError as error:
logger.exception("Unhandled APIError occured.", exc_info=True)
return False
return None
@staticmethod
@ -99,8 +98,7 @@ class EveApiManager():
except evelink.api.APIError as error:
logger.exception("Unhandled APIError occured.", exc_info=True)
return False
return None
@staticmethod
def check_blue_api_is_full(api_id, api_key):
@ -114,6 +112,7 @@ class EveApiManager():
except evelink.api.APIError as error:
logger.exception("Unhandled APIError occured.", exc_info=True)
return None
@staticmethod
@ -128,8 +127,7 @@ class EveApiManager():
except evelink.api.APIError as error:
logger.exception("Unhandled APIError occured.", exc_info=True)
return False
return None
@staticmethod
def api_key_is_valid(api_id, api_key):