File tree Expand file tree Collapse file tree 3 files changed +55
-12
lines changed Expand file tree Collapse file tree 3 files changed +55
-12
lines changed Original file line number Diff line number Diff line change @@ -70,14 +70,38 @@ export default class AppEntity {
70
70
// 2. bind api to app
71
71
console . log ( `Binding api(${ apiId } ) to application(${ appDetail . id } )` ) ;
72
72
73
- await this . request ( {
74
- Action : 'BindApiApp' ,
75
- ApiAppId : appDetail . id ,
76
- ApiId : apiId ,
77
- Environment : environment ,
73
+ // 绑定应用到API接口不支持可重入,第二次绑定会报错。
74
+ // 解决方法是查询Api绑定的应用列表 已经绑定直接跳过,未绑定执行绑定流程
75
+ const apiAppRes : {
76
+ ApiAppApiSet : {
77
+ ApiAppId : string ;
78
+ ApiAppName : string ;
79
+ ApiId : string ;
80
+ ServiceId : string ;
81
+ ApiRegion : string ;
82
+ EnvironmentName : string ;
83
+ AuthorizedTime : string ;
84
+ } [ ] ;
85
+ } = await this . request ( {
86
+ Action : 'DescribeApiBindApiAppsStatus' ,
78
87
ServiceId : serviceId ,
88
+ ApiIds : [ apiId ] ,
89
+ } ) ;
90
+ const isBinded = apiAppRes . ApiAppApiSet . find ( ( item ) => {
91
+ return item . ApiAppId === appDetail . id ;
79
92
} ) ;
80
93
94
+ if ( ! isBinded ) {
95
+ await this . request ( {
96
+ Action : 'BindApiApp' ,
97
+ ApiAppId : appDetail . id ,
98
+ ApiId : apiId ,
99
+ Environment : environment ,
100
+ ServiceId : serviceId ,
101
+ } ) ;
102
+ console . log ( 'BindApiApp success' ) ;
103
+ }
104
+
81
105
return appDetail ;
82
106
}
83
107
Original file line number Diff line number Diff line change @@ -524,8 +524,9 @@ export default class Cos {
524
524
const items = traverseDirSync ( inputs . dir ) ;
525
525
526
526
let key ;
527
- const promises : Promise < PutObjectResult > [ ] = [ ] ;
528
- items . forEach ( ( item ) => {
527
+ let promises : Promise < PutObjectResult > [ ] = [ ] ;
528
+ for ( let i = 0 ; i < items . length ; i ++ ) {
529
+ const item = items [ i ] ;
529
530
// 如果是文件夹跳过
530
531
if ( item . stats . isDirectory ( ) ) {
531
532
return ;
@@ -547,11 +548,25 @@ export default class Cos {
547
548
Body : fs . createReadStream ( item . path ) ,
548
549
} ;
549
550
promises . push ( this . cosClient . putObject ( itemParams ) ) ;
550
- } ) ;
551
- try {
552
- await Promise . all ( promises ) ;
553
- } catch ( err ) {
554
- throw constructCosError ( `API_COS_putObject` , err ) ;
551
+ // fs.createReadStream(item.path) 会一直打开文件,当文件超过1024会报错
552
+ // 解决方案是分段请求,超过100请求一次,请求后会自动关闭文件
553
+ if ( promises . length >= 100 ) {
554
+ try {
555
+ await Promise . all ( promises ) ;
556
+ promises = [ ] ;
557
+ } catch ( err ) {
558
+ throw constructCosError ( `API_COS_putObject` , err ) ;
559
+ }
560
+ }
561
+ }
562
+ // 循环结束后可能还有不足100的文件,此时需要单独再上传
563
+ if ( promises . length >= 1 ) {
564
+ try {
565
+ await Promise . all ( promises ) ;
566
+ promises = [ ] ;
567
+ } catch ( err ) {
568
+ throw constructCosError ( `API_COS_putObject` , err ) ;
569
+ }
555
570
}
556
571
} else if ( inputs . file && ( await fs . existsSync ( inputs . file ) ) ) {
557
572
/** 上传文件 */
Original file line number Diff line number Diff line change @@ -247,6 +247,10 @@ export default class Tag {
247
247
const oldTagVal = item . TagValue ;
248
248
249
249
if ( String ( inputTag . TagValue ) !== String ( oldTagVal ) ) {
250
+ // yml中 tagKey一样,tagVaule变化了 部署时会报错,解决方法是先解绑再绑定新的标签
251
+ detachTags . push ( {
252
+ TagKey : item . TagKey ,
253
+ } ) ;
250
254
attachTags . push ( inputTag ) ;
251
255
} else {
252
256
leftTags . push ( item ) ;
You can’t perform that action at this time.
0 commit comments