mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 14:00:17 +02:00
Abort API refresh when API servers unreachable.
Sorry aboot today.
This commit is contained in:
parent
bba36d9ae0
commit
1daf77709d
@ -63,6 +63,8 @@ def refresh_api(api):
|
|||||||
message="Your API key ID %s no longer meets access mask requirements. Required: %s Got: %s" % (
|
message="Your API key ID %s no longer meets access mask requirements. Required: %s Got: %s" % (
|
||||||
api.api_id, e.required_mask, e.api_mask), level="danger")
|
api.api_id, e.required_mask, e.api_mask), level="danger")
|
||||||
still_valid = False
|
still_valid = False
|
||||||
|
except EveApiManager.ApiServerUnreachableError as e:
|
||||||
|
logger.warn("Error updating API %s\n%s" % (api.api_id, str(e)))
|
||||||
finally:
|
finally:
|
||||||
if not still_valid:
|
if not still_valid:
|
||||||
EveManager.delete_characters_by_api_id(api.api_id, api.user.id)
|
EveManager.delete_characters_by_api_id(api.api_id, api.user.id)
|
||||||
@ -95,6 +97,10 @@ def refresh_user_apis(user):
|
|||||||
|
|
||||||
@periodic_task(run_every=crontab(minute=0, hour="*/3"))
|
@periodic_task(run_every=crontab(minute=0, hour="*/3"))
|
||||||
def run_api_refresh():
|
def run_api_refresh():
|
||||||
|
if not EveApiManager.check_if_api_server_online():
|
||||||
|
logger.warn("Aborted scheduled API key refresh: API server unreachable")
|
||||||
|
return
|
||||||
|
|
||||||
for u in User.objects.all():
|
for u in User.objects.all():
|
||||||
refresh_user_apis.delay(u)
|
refresh_user_apis.delay(u)
|
||||||
|
|
||||||
|
@ -6,6 +6,11 @@ from authentication.states import MEMBER_STATE, BLUE_STATE
|
|||||||
from authentication.models import AuthServicesInfo
|
from authentication.models import AuthServicesInfo
|
||||||
from eveonline.models import EveCharacter
|
from eveonline.models import EveCharacter
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
import requests
|
||||||
|
try:
|
||||||
|
from urllib2 import HTTPError, URLError
|
||||||
|
except ImportError: # py3
|
||||||
|
from urllib.error import URLError, HTTPError
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -41,6 +46,13 @@ class EveApiManager:
|
|||||||
msg = 'Key is invalid.'
|
msg = 'Key is invalid.'
|
||||||
super(EveApiManager.ApiInvalidError, self).__init__(msg, api_id)
|
super(EveApiManager.ApiInvalidError, self).__init__(msg, api_id)
|
||||||
|
|
||||||
|
class ApiServerUnreachableError(Exception):
|
||||||
|
def __init__(self, e):
|
||||||
|
self.error = e
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Unable to reach API servers: %s' % str(self.error)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_characters_from_api(api_id, api_key):
|
def get_characters_from_api(api_id, api_key):
|
||||||
logger.debug("Getting characters from api id %s" % api_id)
|
logger.debug("Getting characters from api id %s" % api_id)
|
||||||
@ -312,6 +324,8 @@ class EveApiManager:
|
|||||||
if int(e.code) in [221, 222]:
|
if int(e.code) in [221, 222]:
|
||||||
raise e
|
raise e
|
||||||
raise EveApiManager.ApiInvalidError(api_id)
|
raise EveApiManager.ApiInvalidError(api_id)
|
||||||
|
except (requests.exceptions.RequestExeception, HTTPError, URLError) as e:
|
||||||
|
raise EveApiManager.ApiServerUnreachableError(e)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise EveApiManager.ApiInvalidError(api_id)
|
raise EveApiManager.ApiInvalidError(api_id)
|
||||||
auth, c = AuthServicesInfo.objects.get_or_create(user=user)
|
auth, c = AuthServicesInfo.objects.get_or_create(user=user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user