diff --git a/appnexus/model.py b/appnexus/model.py index cf79a38..24a4292 100644 --- a/appnexus/model.py +++ b/appnexus/model.py @@ -1,5 +1,6 @@ import logging import re +import time from thingy import Thingy @@ -86,9 +87,18 @@ def profile(self): class Report(Model): - def download(self, **kwargs): + def download(self, retry_count=3, **kwargs): + # Check if the report is ready to download + while self.is_ready() != 'ready' and retry_count > 0: + logger.debug("Report not ready yet; retrying again") + retry_count -= 1 + time.sleep(1) + return self.client.get("report-download", id=self.report_id) + def is_ready(self): + return self.client.get('report', id=self.report_id)['execution_status'] + def create_models(services_list): for service in services_list: