def export_app(self, eid, app_id, version, export_format): app, app_version = rainbond_app_repo.get_rainbond_app_and_version( eid, app_id, version) if not app or not app_version: raise RbdAppNotFound("未找到该应用") # get region TODO: get region by app publish meta info region = self.select_handle_region(eid) region_name = region.region_name export_record = app_export_record_repo.get_export_record( eid, app_id, version, export_format) if export_record: if export_record.status == "success": raise ExportAppError(msg="exported", mes_show="已存在该导出记录", status_code=409) if export_record.status == "exporting": logger.debug("export record exists: event_id :{0}".format( export_record.event_id)) return export_record # did not export, make a new export record # make export data event_id = make_uuid() data = { "event_id": event_id, "group_key": app.app_id, "version": app_version.version, "format": export_format, "group_metadata": self.__get_app_metata(app, app_version) } try: region_api.export_app(region_name, eid, data) except region_api.CallApiError as e: logger.exception(e) raise ExportAppError() params = { "event_id": event_id, "group_key": app_id, "version": version, "format": export_format, "status": "exporting", "enterprise_id": eid, "region_name": region.region_name } return app_export_record_repo.create_app_export_record(**params)
def create_export_repo(self, event_id, export_format, group_key, version): export_record = app_export_record_repo.get_export_record_by_unique_key(group_key, version, export_format) if export_record: return 409, "已存在改导出类型的文件", None if event_id is None: event_id = make_uuid() params = { "event_id": event_id, "group_key": group_key, "version": version, "format": export_format, "status": "exporting" } new_export_record = app_export_record_repo.create_app_export_record(**params) return 200, "success", new_export_record