From 4ef38cbc91152747cd4a3e5486c459bd76097a6c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 31 Oct 2012 11:45:22 -0400 Subject: [PATCH] Added retry mechanism --- python_apps/api_clients/api_client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 9c23ab45e..c160b6458 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -88,6 +88,14 @@ class ApiRequest(object): try: return json.loads(response) except ValueError: return response + def retry(self, n): + """Try to send request n times. If after n times it fails then + we finally raise exception""" + for i in range(0,n-1): + try: return self() + except Exception: pass + return self() + class RequestProvider(object): """ Creates the available ApiRequest instance that can be read from a config file """