Skip to content

Commit 55aade0

Browse files
authored
Merge pull request #222 from annexwu/feature/Nodejs12.16-COSCDBBackup-SetBackTrackDays
Feature/nodejs12.16 coscdb backup set back track days
2 parents 8464736 + e6b94de commit 55aade0

File tree

5,819 files changed

+2449628
-779733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,819 files changed

+2449628
-779733
lines changed

Nodejs12.16-COSCDBBackup/.code.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
{
2-
"serverless-cloud-function-application": {
3-
"Chinese": {
4-
"name": "CDB 备份文件同步到 COS",
5-
"description": "本示例使用定时触发器,完成 CDB 备份文件同步到 COS",
6-
"attention": "",
7-
"author": {
8-
"name": "腾讯云社区开发者"
9-
}
10-
},
11-
"English": {
12-
"name": "COSCDBBackup",
13-
"description": "This demo uses scheduled trigger and SCF to copy CDB backup file to COS automaticly",
14-
"attention": "",
15-
"author": {
16-
"name": "Tencent Cloud Community"
17-
}
18-
},
19-
"runtime": "Nodejs12.16",
20-
"readme": "https://github.com/tencentyun/serverless-demo/tree/master/Nodejs12.16-COSCDBBackup",
21-
"version": "1.0.15",
22-
"tags": [
23-
"Nodejs12.16",
24-
"CDB",
25-
"cos cdb backup"
26-
]
27-
}
28-
}
2+
"serverless-cloud-function-application": {
3+
"Chinese": {
4+
"name": "CDB 备份文件同步到 COS",
5+
"description": "本示例使用定时触发器,完成 CDB 备份文件同步到 COS",
6+
"attention": "该函数模板仅供 COS 控制台使用,请勿自行创建",
7+
"author": {
8+
"name": "腾讯云社区开发者"
9+
}
10+
},
11+
"English": {
12+
"name": "COSCDBBackup",
13+
"description": "This demo uses scheduled trigger and SCF to copy CDB backup file to COS automaticly",
14+
"attention": "This function template is only provided to COS console, please do not use it by yourself",
15+
"author": {
16+
"name": "Tencent Cloud Community"
17+
}
18+
},
19+
"runtime": "Nodejs12.16",
20+
"readme": "https://github.com/tencentyun/serverless-demo/tree/master/Nodejs12.16-COSCDBBackup",
21+
"version": "1.0.20",
22+
"tags": ["Nodejs12.16", "CDB", "cos cdb backup"]
23+
}
24+
}
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
component: scf
22
name: ap-guangzhou_default_COSCDBBackup
33
inputs:
4+
name: COSCDBBackup
45
src:
56
src: ./src
67
handler: index.main_handler
7-
memorySize: 1024
8-
name: COSCDBBackup
9-
region: ap-guangzhou
108
runtime: Nodejs12.16
11-
timeout: 900
12-
environment:
13-
- key: instanceList
14-
value: instanceList
15-
- key: targetBucket
16-
value: targetBucket
17-
- key: targetRegion
18-
value: targetRegion
19-
- key: targetPrefix
20-
value: targetPrefix
21-
triggers:
22-
- type: timer
23-
cronExpression: 0 0 */1 * * * *
24-
enable: true
25-
argument: argument
9+
namespace: default
10+
region: ap-guangzhou
11+
memorySize: 512
12+
timeout: 86400

Nodejs12.16-COSCDBBackup/src/common/CdbSdk.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
const {
22
cdb: {
3-
v20170320: { Client: CdbClient, Models: CdbModels },
3+
v20170320: { Client: CdbClient },
44
},
5-
common: { Credential },
65
} = require('tencentcloud-sdk-nodejs');
76

87
const { retry } = require('./utils');
98

109
class CdbSdk {
1110
constructor({ secretId, secretKey, token }) {
12-
this.credential = new Credential(secretId, secretKey, token);
11+
this.credential = {
12+
secretId,
13+
secretKey,
14+
token,
15+
};
1316
this.requestRetry = retry({
1417
func: (...args) => this.request(...args),
1518
});
1619
}
1720
request({ action, params = {} }) {
18-
return new Promise((resolve, reject) => {
19-
const client = new CdbClient(this.credential);
20-
const req = new CdbModels[`${action}Request`]();
21-
Object.assign(req, params);
22-
client[action](req, (err, response) => {
23-
if (err) {
24-
return reject(err);
25-
}
26-
resolve(response);
21+
return new Promise(async (resolve, reject) => {
22+
const { Region, ...args } = params;
23+
const client = new CdbClient({
24+
credential: this.credential,
25+
region: Region,
2726
});
27+
try {
28+
await client.request(action, args, (err, response) => {
29+
if (err) {
30+
return reject(err);
31+
}
32+
resolve(response);
33+
});
34+
} catch (error) {}
2835
});
2936
}
3037
}

0 commit comments

Comments
 (0)