diff -r c3252b31b98a -r 0aedb8dd6861 scc_access/scc_access.py --- a/scc_access/scc_access.py Thu Oct 04 10:38:50 2018 +0200 +++ b/scc_access/scc_access.py Thu Oct 04 11:37:15 2018 +0200 @@ -167,7 +167,7 @@ self.download_files(measurement_id, 'scc_plots', download_url) def rerun_processing(self, measurement_id, monitor=True): - measurement = self.get_measurement(measurement_id) + measurement, status = self.get_measurement(measurement_id) if measurement: request = self.session.get(measurement.rerun_processing_url, auth=self.auth, @@ -186,7 +186,7 @@ logger.debug("Started rerun_all procedure.") logger.debug("Getting measurement %s" % measurement_id) - measurement = self.get_measurement(measurement_id) + measurement, status = self.get_measurement(measurement_id) if measurement: logger.debug("Attempting to rerun all processing through %s." % measurement.rerun_all_url) @@ -209,8 +209,10 @@ """ logger.info("--- Processing started on %s. ---" % datetime.datetime.now()) # Upload file + logger.info("--- Uploading file") measurement_id = self.upload_file(filename, system_id, rs_filename=rs_filename) + logger.info("--- Monitoring processing") measurement = self.monitor_processing(measurement_id) return measurement @@ -220,29 +222,34 @@ # try to deal with error 404 error_count = 0 error_max = 6 + time_sleep = 10 # try to wait for measurement to appear in API measurement = None - while error_count < error_max or measurement is None: - measurement = self.get_measurement(measurement_id) - if measurement is None: + logger.info("looking for measurement %s in SCC", measurement_id) + while error_count < error_max: + time.sleep(time_sleep) + measurement, status = self.get_measurement(measurement_id) + if status != 200 and error_count < error_max: + logger.error("measurement not found. waiting %ds", time_sleep) error_count += 1 - time.sleep(10) + else: + break if error_count == error_max: logger.critical("measurement %s doesn't seem to exist", measurement_id) + sys.exit(1) + + logger.info('measurement %s found', measurement_id) if measurement is not None: error_count = 0 while measurement.is_running: 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) - + measurement, status = self.get_measurement(measurement_id) - logger.info("Measurement processing finished (status: %s, %s, %s)." % (measurement.upload, - measurement.pre_processing, - measurement.processing)) + logger.info("Measurement processing finished (status: %s, %s, %s).",measurement.upload, measurement.pre_processing, measurement.processing) if measurement.pre_processing == 127: logger.info("Downloading preprocessed files.") self.download_preprocessed(measurement_id) @@ -281,20 +288,20 @@ # maybe the measurements isn't already available on the database. if response.status_code == 404: - return None + return None, 404 if response.status_code != 200: logger.error('Could not access API. Status code %s.' % response.status_code) - sys.exit(1) + return None, response.status_code response_dict = response.json() if response_dict: - measurement = Measurement(self.base_url,response_dict) - return measurement + measurement = Measurement(self.base_url, response_dict) + return measurement, response.status_code else: logger.error("No measurement with id %s found on the SCC." % measurement_id) - return None + return None, response.status_code def delete_measurement(self, measurement_id): """ Deletes a measurement with the provided measurement id. The user @@ -304,7 +311,7 @@ NOT through the API. """ # Get the measurement object - measurement = self.get_measurement(measurement_id) + measurement, status = self.get_measurement(measurement_id) # Check that it exists if measurement is None: