refactor(model): Refactor the model download logic, support multiple solutions, and optimize automatic resource deployment - #105
Conversation
81f9513 to
ac0e0a8
Compare
| private async _handleOssAutoDeployment(region: IRegion, credential: any) { | ||
| let ossEndpoint = `https://oss-${region}.aliyuncs.com`; | ||
| if (process.env.FC_REGION === region) { | ||
| ossEndpoint = `oss-${region}-internal.aliyuncs.com`; |
There was a problem hiding this comment.
这种之前线上测试过吗? 最好预发杭州和预发新加坡都测试下
| logger.info(`ossAuto code to ${ossEndpoint}`); | ||
| const oss = new OSS(region, credential as ICredentials, ossEndpoint); | ||
| const { ossBucket } = await oss.deploy(); | ||
| logger.write( |
There was a problem hiding this comment.
oss auto 的逻辑,泽文优化的一版的, 你看下他优化后的代码, auto 包应该有一些变化,支持更多参数自定义
| throw new Error(errorMessage); | ||
| } | ||
| const { nasConfig, vpcConfig, ossMountConfig } = this.local; | ||
| logger.debug( |
There was a problem hiding this comment.
这个日志建议 info, 很重要, 涉及到调用下载服务那边的入参,方便查问题
| const { AccountID: accountID } = await this.inputs.getCredential(); | ||
| const { credential } = this.inputs; | ||
| const { region, supplement, annotations } = this.inputs.props; | ||
| const { supplement, annotations } = this.inputs.props; |
There was a problem hiding this comment.
线上没有这个, supplement 直接remove 掉吧
| files: modelConfig.files, | ||
| conflictResolution: modelConfig?.downloadStrategy?.conflictResolution || 'overwrite', | ||
| mode: modelConfig?.downloadStrategy?.mode || 'once', | ||
| timeout: modelConfig?.downloadStrategy?.timeout, |
There was a problem hiding this comment.
这个默认值我们先定义为 40 分钟, 2400s
| syncStrategy: process.env.MODEL_DOWNLOAD_STRATEGY || 'incremental_once', | ||
| }; | ||
|
|
||
| if (typeof ossMountConfig === 'object' && ossMountConfig?.mountPoints) { |
There was a problem hiding this comment.
这个时候按道理,应该没有 auto 的情况,基本都是正确的情况, 除非 fc3 props 中传过来的值就不对, 对吧
| @@ -79,363 +64,233 @@ export class Model { | |||
| this.envName = envName; | |||
| const name = `${projectName}$${envName}$${functionName}`; | |||
There was a problem hiding this comment.
- 这个 deploy 和 remove 中 name 的获取有重复代码, 提取成一个 method 吧
-
${uid}$ ${projectName}$${envName}$${functionName} 最后前面再加一个 uid, 因为下载服务也是 region 化的,region 就不用传了, 但是 uid 需要加上,不然有 name 冲突
| if (process.env.artifact_endpoint) { | ||
| return process.env.artifact_endpoint; | ||
| } | ||
| return DEFAULT_ENDPOINT; |
There was a problem hiding this comment.
devs.{region}.aliyuncs.com
| export const NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT: number = | ||
| parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT as string, 10) || 60 * 1000; | ||
| export const NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT: number = | ||
| parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT as string, 10) || 86400 * 1000; |
| }`, | ||
| }); | ||
|
|
||
| logger.info(`new models service init, ARTIFACT_ENDPOINT endpoint: ${config.endpoint}`); |
|
|
||
| let endpoint: string; | ||
|
|
||
| endpoint = 'devs-pre.cn-hangzhou.aliyuncs.com'; |
There was a problem hiding this comment.
统一提取到 utils.ts, 还有那个 name generate
| connectTimeout: NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT, | ||
| userAgent: `${ | ||
| this.inputs.userAgent || | ||
| `Component:cap-model;Nodejs:${process.version};OS:${process.platform}-${process.arch}` |
| } | ||
| } | ||
|
|
||
| private _displayProgressComplete(filePath: string, currentBytes: number, totalBytes: number) { |
| } | ||
| } | ||
|
|
||
| private _getSourcePath(source: any, sourceUri: string, validSourcePattern: RegExp): string { |
| } | ||
| } | ||
|
|
||
| private _getSourcePath(source: any, sourceUri: string, validSourcePattern: RegExp): string { |
There was a problem hiding this comment.
validSourcePattern 不用作为参数
| return new DevClient(config); | ||
| } | ||
|
|
||
| getSource(uri, file, nasMountPoints, ossMountPoints, targetUri) { |
There was a problem hiding this comment.
resolveSourceAndTarget, 举个例子,取一个有意义的字段
| return; | ||
| } | ||
|
|
||
| if (!_.isEmpty(files)) { |
There was a problem hiding this comment.
if(_.isEmpty(files)){
log.warn();
return
}
c9e5201 to
46c49fd
Compare
| readTimeout: NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT, | ||
| connectTimeout: NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT, | ||
| userAgent: `${inputs.userAgent || | ||
| `Component:fun-art;Nodejs:${process.version};OS:${process.platform}-${process.arch}` |
| : true; | ||
|
|
||
| if (!needDownload) { | ||
| logger.info(`[Download-model] ${file.source.path} The file has been downloaded..`); |
|
|
||
| // 文件下载失败,抛出错误 | ||
| if (failureCount > 0) { | ||
| throw new Error(`[Download-model] ${failureCount} out of ${filesNeed.length} files failed to download.`); |
There was a problem hiding this comment.
这个能打印下原始错误或者 rid, 方便能让ohye 查下后端的问题
| const { credential: { AccountID: accountID } } = this.inputs; | ||
| const projectName = getEnvVariable('ALIYUN_DEVS_REMOTE_PROJECT_NAME'); | ||
| const envName = getEnvVariable('ALIYUN_DEVS_REMOTE_ENV_NAME'); | ||
| this.name = `${getUuid(String(accountID))}$${projectName}$${envName}$${functionName}`; |
There was a problem hiding this comment.
我建议前缀最好还是有 uid, 完全 uuid 都不知道是哪个用户的了
${uid}{projectname}{uuid} 这种同时具备可读性和唯一性
83b90ea to
87f48c7
Compare
a39f5cd to
c1f4a28
Compare
…solutions, and optimize automatic resource deployment Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
c1f4a28 to
e5c356b
Compare
No description provided.