Added better error logging and some documentation

This commit is contained in:
2011-08-26 10:26:21 +01:00
parent dbd1ec1329
commit 9dd23d857c
2 changed files with 8 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from xml.dom import minidom from xml.dom import minidom
import logging import logging
@@ -49,7 +50,7 @@ def import_apikey(api_userid, api_key, user=None, force_cache=False, **kwargs):
try: try:
import_apikey_func(api_userid, api_key, user, force_cache, log) import_apikey_func(api_userid, api_key, user, force_cache, log)
except (APIAccessException, DocumentRetrievalError), exc: except (APIAccessException, DocumentRetrievalError), exc:
log.error('Error importing API Key - flagging for retry') log.error('Error importing API Key - flagging for retry', exc_info=sys.exc_info(), extra={'data': {'api_userid': api_userid, 'api_key': api_key}})
import_apikey.retry(args=[api_userid, api_key, user, force_cache], exc=exc, kwargs=kwargs) import_apikey.retry(args=[api_userid, api_key, user, force_cache], exc=exc, kwargs=kwargs)
@@ -63,7 +64,7 @@ def import_apikey_result(api_userid, api_key, user=None, force_cache=False, call
try: try:
results = import_apikey_func(api_userid, api_key, user, force_cache, log) results = import_apikey_func(api_userid, api_key, user, force_cache, log)
except (APIAccessException, DocumentRetrievalError), exc: except (APIAccessException, DocumentRetrievalError), exc:
log.error('Error importing API Key - flagging for retry') log.error('Error importing API Key - flagging for retry', exc_info=sys.exc_info(), extra={'data': {'api_userid': api_userid, 'api_key': api_key}})
import_apikey_result.retry(args=[api_userid, api_key, user, force_cache, callback], exc=exc, kwargs=kwargs) import_apikey_result.retry(args=[api_userid, api_key, user, force_cache, callback], exc=exc, kwargs=kwargs)
else: else:
if callback: if callback:

View File

@@ -73,12 +73,15 @@ def import_eve_character_func(character_id, api_key=None, user_id=None, logger=l
values = d['result'] values = d['result']
pchar, created = EVEPlayerCharacter.objects.get_or_create(id=character_id) pchar, created = EVEPlayerCharacter.objects.get_or_create(id=character_id)
# Set the character's name, avoid oddities in the XML feed
if not values['characterName'] == {}: if not values['characterName'] == {}:
pchar.name = values['characterName'] pchar.name = values['characterName']
else: else:
pchar.name = "" pchar.name = ""
pchar.security_status = values['securityStatus'] pchar.security_status = values['securityStatus']
# Set corporation and join date
corp, created = EVEPlayerCorporation.objects.get_or_create(id=values['corporationID']) corp, created = EVEPlayerCorporation.objects.get_or_create(id=values['corporationID'])
from eve_api.tasks.corporation import import_corp_details from eve_api.tasks.corporation import import_corp_details
if created or not corp.name or corp.api_last_updated < (datetime.utcnow() - timedelta(hours=12)): if created or not corp.name or corp.api_last_updated < (datetime.utcnow() - timedelta(hours=12)):
@@ -87,12 +90,14 @@ def import_eve_character_func(character_id, api_key=None, user_id=None, logger=l
pchar.corporation = corp pchar.corporation = corp
pchar.corporation_date = values['corporationDate'] pchar.corporation_date = values['corporationDate']
# Derrive Race value from the choices
for v in API_RACES_CHOICES: for v in API_RACES_CHOICES:
val, race = v val, race = v
if race == values['race']: if race == values['race']:
pchar.race = val pchar.race = val
break break
# If we have a valid API key, import the full character sheet
if api_key and user_id: if api_key and user_id:
auth_params = {'userID': user_id, 'apiKey': api_key, 'characterID': character_id } auth_params = {'userID': user_id, 'apiKey': api_key, 'characterID': character_id }
try: try: