Beispiel #1
0
 def import_csv_data(self):  # noqa
     """Perform import sequence for the block."""
     try:
         for row in self.row_converters_from_csv():
             try:
                 ie_status = self.converter.get_job_status()
                 if ie_status and ie_status == \
                    all_models.ImportExport.STOPPED_STATUS:
                     raise exceptions.ImportStoppedException()
                 row.process_row()
             except exceptions.ImportStoppedException:
                 raise
             except ValueError as err:
                 db.session.rollback()
                 msg = err.message or errors.UNEXPECTED_ERROR
                 row.add_error(errors.ERROR_TEMPLATE, message=msg)
                 logger.exception(msg)
             except Exception:  # pylint: disable=broad-except
                 db.session.rollback()
                 row.add_error(errors.UNKNOWN_ERROR)
                 logger.exception(errors.UNEXPECTED_ERROR)
             self._update_info(row)
             _app_ctx_stack.top.sqlalchemy_queries = []
     except exceptions.ImportStoppedException:
         raise
     except Exception:  # pylint: disable=broad-except
         logger.exception(errors.UNEXPECTED_ERROR)
     finally:
         db.session.commit_hooks_enable_flag.enable()
         is_final_commit_required = not (self.converter.dry_run
                                         or self.ignore)
         if is_final_commit_required:
             db.session.commit()
Beispiel #2
0
def handle_import_stop(**kwargs):
    """Handle import stop"""
    try:
        ie_job = import_export.get(kwargs["id2"])
        if ie_job.status in ("Analysis", "In Progress", "Blocked"):
            ie_job.status = "Stopped"
            ie_job.end_at = datetime.utcnow()
            # Stop tasks only on non local instance
            if getattr(settings, "APPENGINE_INSTANCE", "local") != "local":
                stop_ie_bg_tasks(ie_job)
            db.session.commit()
            expire_ie_cache(ie_job)
            return make_import_export_response(ie_job.log_json())
        if ie_job.status == "Stopped":
            raise models_exceptions.ImportStoppedException()
    except wzg_exceptions.Forbidden:
        raise
    except models_exceptions.ImportStoppedException:
        raise wzg_exceptions.BadRequest(app_errors.IMPORT_STOPPED_WARNING)
    except Exception as e:
        logger.exception(e.message)
        raise wzg_exceptions.BadRequest(
            app_errors.INCORRECT_REQUEST_DATA.format(job_type="Import"))
    # Need to implement a better solution in order to identify specific
    # errors like here
    raise wzg_exceptions.BadRequest(app_errors.WRONG_STATUS)