Skip to content

Commit cbf068e

Browse files
author
mamba
authored
Merge pull request #2 from serverless-cd/ots
Ots
2 parents 1b26877 + 70773c6 commit cbf068e

File tree

4 files changed

+154
-96
lines changed

4 files changed

+154
-96
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: publish package to serverless-hub
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: '3.x'
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: 12
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install setuptools wheel twine
23+
pip install requests
24+
- name: Build
25+
run: |
26+
npm run build
27+
- name: Add publish file
28+
run: |
29+
wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py
30+
ls
31+
- name: Publish package
32+
env:
33+
publish_token: ${{ secrets.alibaba_registry_publish_token }}
34+
run: |
35+
ls
36+
python hub-publish.py

dist/index.js

Lines changed: 85 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Component
22
Name: cd-generate
33
Provider:
44
- 阿里云
5-
Version: 0.0.13
5+
Version: 0.0.14
66
Description: 服务于serverless-cd初始化组件
77
HomePage: https://cd.serverless-devs.com
88
Tags:

src/resource/tablestore/index.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ import * as generateDbParams from "./generate-db-params";
66
import logger from "../../common/logger";
77
import { OTS_INSTANCE_NAME } from "../../constants";
88

9+
enum OtsAccess {
10+
OTS = 'ots',
11+
TABLE_STORE = 'tablestore',
12+
}
13+
914
export default class Ots {
1015
client: Client;
1116
popClient: any;
1217
dbConfig: any;
1318
envConfig: any;
19+
endpoint: string;
1420

1521
constructor(envConfig: IProps) {
1622
this.envConfig = envConfig;
@@ -20,15 +26,7 @@ export default class Ots {
2026
endpoint: `https://ots.${envConfig.REGION}.aliyuncs.com`,
2127
apiVersion: "2016-06-20",
2228
});
23-
24-
this.client = new Client({
25-
accessKeyId: envConfig.ACCESS_KEY_ID,
26-
accessKeySecret: envConfig.ACCESS_KEY_SECRET,
27-
// securityToken: credentials.SecurityToken,
28-
endpoint: `https://${envConfig.OTS_INSTANCE_NAME}.${envConfig.REGION}.ots.aliyuncs.com`,
29-
instancename: envConfig.OTS_INSTANCE_NAME,
30-
maxRetries: 20, // 默认20次重试,可以省略此参数。
31-
});
29+
this.makeClient();
3230

3331
this.dbConfig = [
3432
{
@@ -62,6 +60,20 @@ export default class Ots {
6260
];
6361
}
6462

63+
makeClient(access: OtsAccess = OtsAccess.OTS) {
64+
const envConfig = this.envConfig;
65+
this.endpoint = `https://${envConfig.OTS_INSTANCE_NAME}.${envConfig.REGION}.${access}.aliyuncs.com`;
66+
67+
this.client = new Client({
68+
accessKeyId: envConfig.ACCESS_KEY_ID,
69+
accessKeySecret: envConfig.ACCESS_KEY_SECRET,
70+
// securityToken: credentials.SecurityToken,
71+
endpoint: this.endpoint,
72+
instancename: envConfig.OTS_INSTANCE_NAME,
73+
maxRetries: 20, // 默认20次重试,可以省略此参数。
74+
});
75+
}
76+
6577
// 初始化实例
6678
async initInstance() {
6779
const popClient = this.popClient;
@@ -103,7 +115,17 @@ export default class Ots {
103115
for (const { name, indexName, genTableParams, genIndexParams } of this
104116
.dbConfig) {
105117
logger.debug(`handler ${name} start`);
106-
await this.handlerTable(name, genTableParams(name, this.envConfig));
118+
try {
119+
await this.handlerTable(name, genTableParams(name, this.envConfig));
120+
} catch (ex) {
121+
logger.debug(`handler table error: ${ex.message}`);
122+
if (ex?.code === 'NetworkingError' && ex?.message.startsWith('getaddrinfo ENOTFOUND')) {
123+
this.makeClient(OtsAccess.TABLE_STORE);
124+
await this.handlerTable(name, genTableParams(name, this.envConfig));
125+
} else {
126+
throw ex;
127+
}
128+
}
107129

108130
if (indexName) {
109131
await this.handlerIndex(

0 commit comments

Comments
 (0)