mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 14:30:17 +02:00
Added a check to insure that during the api refresh the server is online for every user minimizes chances of database wipe
This commit is contained in:
parent
d1159d177a
commit
0fa2ceec48
@ -11,6 +11,7 @@ from eveonline.managers import EveManager
|
||||
from services.managers.eve_api_manager import EveApiManager
|
||||
from util.common_task import deactivate_services
|
||||
|
||||
|
||||
def update_jabber_groups(user):
|
||||
syncgroups = SyncGroupCache.objects.filter(user=user)
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
@ -123,36 +124,39 @@ def run_databaseUpdate():
|
||||
@periodic_task(run_every=crontab(minute=0, hour="*/3"))
|
||||
def run_api_refresh():
|
||||
users = User.objects.all()
|
||||
for user in users:
|
||||
api_key_pairs = EveManager.get_api_key_pairs(user.id)
|
||||
if api_key_pairs:
|
||||
valid_key = False
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
# We do a check on the authservice info to insure that we shoud run the check
|
||||
# No point in running the check on people who arn't on services
|
||||
print 'Running update on user: '+user.username
|
||||
if authserviceinfo.main_char_id:
|
||||
if authserviceinfo.main_char_id != "":
|
||||
for api_key_pair in api_key_pairs:
|
||||
print 'Running on '+api_key_pair.api_id+':'+api_key_pair.api_key
|
||||
if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
|
||||
# Update characters
|
||||
characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key)
|
||||
EveManager.update_characters_from_list(characters)
|
||||
valid_key = True
|
||||
else:
|
||||
EveManager.delete_characters_by_api_id(api_key_pair.api_id, user)
|
||||
EveManager.delete_api_key_pair(api_key_pair.api_id, api_key_pair.api_key)
|
||||
|
||||
if valid_key:
|
||||
# Check our main character
|
||||
main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
|
||||
if main_alliance_id == settings.ALLIANCE_ID:
|
||||
pass
|
||||
for user in users:
|
||||
# Check if the api server is online
|
||||
if EveApiManager.check_if_api_server_online():
|
||||
api_key_pairs = EveManager.get_api_key_pairs(user.id)
|
||||
if api_key_pairs:
|
||||
valid_key = False
|
||||
authserviceinfo = AuthServicesInfo.objects.get(user=user)
|
||||
# We do a check on the authservice info to insure that we shoud run the check
|
||||
# No point in running the check on people who arn't on services
|
||||
print 'Running update on user: '+user.username
|
||||
if authserviceinfo.main_char_id:
|
||||
if authserviceinfo.main_char_id != "":
|
||||
for api_key_pair in api_key_pairs:
|
||||
print 'Running on '+api_key_pair.api_id+':'+api_key_pair.api_key
|
||||
if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
|
||||
# Update characters
|
||||
characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key)
|
||||
EveManager.update_characters_from_list(characters)
|
||||
valid_key = True
|
||||
else:
|
||||
EveManager.delete_characters_by_api_id(api_key_pair.api_id, user)
|
||||
EveManager.delete_api_key_pair(api_key_pair.api_id, api_key_pair.api_key)
|
||||
|
||||
if valid_key:
|
||||
# Check our main character
|
||||
main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
|
||||
if main_alliance_id == settings.ALLIANCE_ID:
|
||||
pass
|
||||
else:
|
||||
deactivate_services(user)
|
||||
else:
|
||||
#nuke it
|
||||
deactivate_services(user)
|
||||
else:
|
||||
#nuke it
|
||||
deactivate_services(user)
|
||||
else:
|
||||
print 'No main_char_id set'
|
||||
else:
|
||||
print 'No main_char_id set'
|
@ -86,3 +86,15 @@ class EveApiManager():
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def check_if_api_server_online():
|
||||
try:
|
||||
api = evelink.api.API()
|
||||
server = evelink.server.Server(api=api)
|
||||
info = server.server_status()
|
||||
return True
|
||||
except evelink.api.APIError as error:
|
||||
return False
|
||||
|
||||
return False
|
Loading…
x
Reference in New Issue
Block a user