From 2021da2c92b0a2eefeffb321c07355884d70a9cc Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 25 Aug 2011 10:28:53 +0100 Subject: [PATCH] Add retry to API import errors, and catch DocumentRetreivalErrors --- app/eve_api/tasks/account.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/eve_api/tasks/account.py b/app/eve_api/tasks/account.py index f6c73fd..cd391fc 100644 --- a/app/eve_api/tasks/account.py +++ b/app/eve_api/tasks/account.py @@ -40,18 +40,20 @@ def queue_apikey_updates(update_delay=86400, batch_size=50): @task(ignore_result=True) -def import_apikey(api_userid, api_key, user=None, force_cache=False): +def import_apikey(api_userid, api_key, user=None, force_cache=False, **kwargs): """ Imports a EVE Account from the API, doesn't return a result """ log = import_apikey.get_logger() try: import_apikey_func(api_userid, api_key, user, force_cache, log) - except: - log.error('Error importing API Key') + except (APIAccessException, DocumentRetrievalError), exc: + log.error('Error importing API Key - flagging for retry') + import_apikey.retry(args=[api_userid, api_key, user, force_cache], exc=exc, kwargs=kwargs) + @task() -def import_apikey_result(api_userid, api_key, user=None, force_cache=False, callback=None): +def import_apikey_result(api_userid, api_key, user=None, force_cache=False, callback=None, **kwargs): """ Imports a EVE Account from the API and returns the account object when completed """ @@ -59,8 +61,9 @@ def import_apikey_result(api_userid, api_key, user=None, force_cache=False, call log = import_apikey_result.get_logger() try: results = import_apikey_func(api_userid, api_key, user, force_cache, log) - except APIAccessException, exc: + except (APIAccessException, DocumentRetrievalError), exc: log.error('Error importing API Key - flagging for retry') + import_apikey_result.retry(args=[api_userid, api_key, user, force_cache, callback], exc=exc, kwargs=kwargs) else: if callback: subtask(callback).delay(account=results)