add checking to measurements being available in REST API send_rs_data

Thu, 04 Oct 2018 10:30:59 +0200

author
madrouin@astronotus.lmd.polytechnique.fr
date
Thu, 04 Oct 2018 10:30:59 +0200
branch
send_rs_data
changeset 24
a6ed20f50a58
parent 23
bbaf82cd6e71
child 25
c3252b31b98a

add checking to measurements being available in REST API

scc_access/scc_access.py file | annotate | diff | comparison | revisions
--- a/scc_access/scc_access.py	Wed Oct 03 18:00:23 2018 +0200
+++ b/scc_access/scc_access.py	Thu Oct 04 10:30:59 2018 +0200
@@ -1,18 +1,18 @@
-import requests
-requests.packages.urllib3.disable_warnings()
-
-import sys
-import urlparse
 import argparse
+import datetime
+import logging
 import os
 import re
+import StringIO
+import sys
 import time
-import StringIO
+import urlparse
 from zipfile import ZipFile
-import datetime
-import logging
+
+import requests
 import yaml
 
+requests.packages.urllib3.disable_warnings()
 
 logger = logging.getLogger(__name__)
 
@@ -22,7 +22,7 @@
 
 
 class SCC:
-    """ A simple class that will attempt to upload a file on the SCC server.
+    """A simple class that will attempt to upload a file on the SCC server.
 
     The uploading is done by simulating a normal browser session. In the current
     version no check is performed, and no feedback is given if the upload
@@ -217,14 +217,27 @@
     def monitor_processing(self, measurement_id):
         """ Monitor the processing progress of a measurement id"""
 
-        measurement = self.get_measurement(measurement_id)
+        # try to deal with error 404
+        error_count = 0
+        error_max = 6
+
+        measurement = None
+        while error_count < error_max or measurement is None:
+            measurement = self.get_measurement(measurement_id)
+            if measurement is None:
+                error_count += 1
+            time.sleep(10)
+
+        if error_count == error_max:
+            logger.critical("measurement %s doesn't seem to exist", measurement_id)
+
         if measurement is not None:
             while measurement.is_running:
-                logger.info("Measurement is being processed (status: %s, %s, %s). Please wait." % (measurement.upload,
-                                                                                                   measurement.pre_processing,
-                                                                                                   measurement.processing))
+                logger.info("Measurement is being processed (status: %s, %s, %s). Please wait.", measurement.upload, measurement.pre_processing, measurement.processing)
                 time.sleep(10)
                 measurement = self.get_measurement(measurement_id)
+
+
             logger.info("Measurement processing finished (status: %s, %s, %s)." % (measurement.upload,
                                                                                    measurement.pre_processing,
                                                                                    measurement.processing))
@@ -266,7 +279,7 @@
 
         if response.status_code != 200:
             logger.error('Could not access API. Status code %s.' % response.status_code)
-            sys.exit(1)
+            return None
 
         response_dict = response.json()
 

mercurial