Skip to content

Commit 50936a7

Browse files
author
dfounderliu
committed
fix status
1 parent 52f4280 commit 50936a7

9 files changed

+56
-60
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ module.exports = {
4343
}
4444
],
4545
'no-alert': 'error',
46-
'no-console': 'error',
4746
'no-const-assign': 'error',
4847
'no-else-return': 'error',
4948
'no-empty': 'off',

Changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# 变更历史
22

3+
4+
5+
## 2020-02-06
6+
* 修复rollback操作可能出现函数状态错误问题
7+
* 优化函数状态检测部分代码
8+
39
## 2019-11-26
410
* 更新函数状态,提高部署成功率

deploy/lib/deployFunction.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,7 @@ class DeployFunction extends AbstractHandler {
2121
}
2222
this.serverless.cli.log('Updating code... ')
2323
await this.updateFunctionCode(ns, funcObject)
24-
// when update code Status is Active, continue
25-
let status = 'Updating'
26-
let times = 90
27-
while (status == 'Updating' || status == 'Creating') {
28-
const tempFunc = await this.getFunction(ns, funcObject.FuncName)
29-
status = tempFunc.Status
30-
await utils.sleep(1000)
31-
times = times - 1
32-
if (times <= 0) {
33-
throw `Function ${funcObject.FuncName} update failed`
34-
}
35-
}
36-
if (status != 'Active') {
24+
if ((await this.checkStatus(ns, funcObject)) == false) {
3725
throw `Function ${funcObject.FuncName} update failed`
3826
}
3927
this.serverless.cli.log('Updating configure... ')
@@ -43,6 +31,18 @@ class DeployFunction extends AbstractHandler {
4331
return null
4432
}
4533

34+
async checkStatus(ns, funcObject) {
35+
let status = 'Updating'
36+
let times = 90
37+
while ((status == 'Updating' || status == 'Creating') && times > 0) {
38+
const tempFunc = await this.getFunction(ns, funcObject.FuncName)
39+
status = tempFunc.Status
40+
await utils.sleep(1000)
41+
times = times - 1
42+
}
43+
return status != 'Active' ? false : true
44+
}
45+
4646
async addRole() {
4747
try {
4848
const roleName = 'SCF_QcsRole'

deploy/tencentDeploy.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,7 @@ class TencentDeploy {
6666
this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`)
6767
await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags)
6868

69-
// Function status
70-
let status = 'Updating'
71-
let times = 90
72-
while (status == 'Updating' || status == 'Creating') {
73-
const tempFunc = await func.getFunction('default', funcObject.FuncName)
74-
status = tempFunc.Status
75-
await utils.sleep(1000)
76-
times = times - 1
77-
if (times <= 0) {
78-
throw `Function ${funcObject.FuncName} create/update failed`
79-
}
80-
}
81-
if (status != 'Active') {
69+
if ((await func.checkStatus('default', funcObject)) == false) {
8270
throw `Function ${funcObject.FuncName} create/update failed`
8371
}
8472

deploy/tencentDeployFunction.js

+2-25
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,7 @@ class TencentDeployFunction {
7979
const oldFunc = await func.deploy('default', funcObject)
8080
this.serverless.cli.log(`Created function ${funcObject.FuncName}`)
8181

82-
// when update code Status is Active, continue
83-
let status = 'Updating'
84-
let times = 90
85-
while (status == 'Updating' || status == 'Creating') {
86-
const tempFunc = await func.getFunction('default', funcObject.FuncName)
87-
status = tempFunc.Status
88-
await utils.sleep(1000)
89-
times = times - 1
90-
if (times <= 0) {
91-
throw `Function ${funcObject.FuncName} create/update failed`
92-
}
93-
}
94-
if (status != 'Active') {
82+
if ((await func.checkStatus('default', funcObject)) == false) {
9583
throw `Function ${funcObject.FuncName} create/update failed`
9684
}
9785

@@ -101,18 +89,7 @@ class TencentDeployFunction {
10189
this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`)
10290
await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags)
10391

104-
// Function status
105-
status = 'Updating'
106-
while (status == 'Updating' || status == 'Creating') {
107-
const tempFunc = await func.getFunction('default', funcObject.FuncName)
108-
status = tempFunc.Status
109-
await utils.sleep(1000)
110-
times = times - 1
111-
if (times <= 0) {
112-
throw `Function ${funcObject.FuncName} create/update failed`
113-
}
114-
}
115-
if (status != 'Active') {
92+
if ((await func.checkStatus('default', funcObject)) == false) {
11693
throw `Function ${funcObject.FuncName} create/update failed`
11794
}
11895

invoke/tencentInvoke.js

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class TencentInvoke {
2727
this.options = await provider.getUserCred(this.options)
2828
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
2929
try {
30-
const options = {
31-
region: this.options.region
32-
}
3330
const invokeHandler = new Invoke(this.options, this.serverless)
3431
let context = null
3532
if (this.options.data) {

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-tencent-scf",
3-
"version": "0.1.33",
3+
"version": "0.1.34",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.",
55
"main": "index.js",
66
"author": "Tencent Cloud, Inc.",
@@ -44,8 +44,8 @@
4444
"tencentcloud-sdk-nodejs": "^3.0.87",
4545
"universal-analytics": "^0.4.20",
4646
"tencent-login": "^0.1.6",
47-
"serverless-tencent-tools": "^0.0.10",
48-
"serverless-tencent-auth-tool": "^1.0.13"
47+
"serverless-tencent-tools": "^0.0.11",
48+
"serverless-tencent-auth-tool": "^1.0.18"
4949
},
5050
"devDependencies": {
5151
"coveralls": "^3.0.5",

provider/tencentProvider.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ const util = require('util')
77
const QRCode = require('qrcode')
88
const TencentLogin = require('tencent-login')
99
const tencentcloud = require('tencentcloud-sdk-nodejs')
10-
const { GetUserAuthInfo } = require('serverless-tencent-tools').Account
10+
const serverlessTencentTools = require('serverless-tencent-tools')
11+
const { GetUserAuthInfo } = serverlessTencentTools.Account
12+
const { DataReport } = serverlessTencentTools.Others.DataReport
1113
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js')
1214
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js')
1315
const AbstractModel = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_model')
1416
const AbstractClient = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client')
17+
1518
const constants = {
1619
providerName: 'tencent'
1720
}
@@ -50,6 +53,19 @@ class TencentProvider {
5053
this.getCredentials(this.serverless, this.options)
5154
this.serverless.setProvider(constants.providerName, this)
5255
this.provider = this
56+
let commands = ''
57+
const commandsAttr = this.serverless.pluginManager.cliCommands
58+
for (let i = 0; i < commandsAttr.length; i++) {
59+
commands = commands + (i == 0 ? '' : '_') + commandsAttr[i]
60+
}
61+
this.reportInputs = {
62+
name: 'serverless-tencent-scf',
63+
project: this.serverless.service.service,
64+
action: commands
65+
}
66+
try {
67+
new DataReport().report(this.reportInputs)
68+
} catch (e) {}
5369
}
5470

5571
static getProviderName() {
@@ -75,14 +91,19 @@ class TencentProvider {
7591
})
7692
options.credentials.tencent_appid = appid.AppId
7793
options.credentials.tencent_owneruin = appid.OwnerUin
94+
this.tempUin = appid.OwnerUin
7895
}
7996
return options
8097
}
8198

8299
async getUserAuth(uin) {
83100
try {
101+
try {
102+
this.reportInputs.uin = uin
103+
new DataReport().report(this.reportInputs)
104+
} catch (e) {}
84105
const getUserAuthInfo = new GetUserAuthInfo()
85-
const result = await getUserAuthInfo.isAuth(uin, { client: 'plugin' })
106+
const result = await getUserAuthInfo.isAuth(uin, this.reportInputs)
86107
if (result['Error'] == true) {
87108
console.log('Failed to get real name authentication result.')
88109
process.exit(-1)

rollback/tencentRollback.js

+8
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,17 @@ class TencentRollback {
8888
const oldFunc = await func.deploy('default', funcObject)
8989
this.serverless.cli.log(`Rollback function ${funcObject.FuncName}`)
9090

91+
if ((await func.checkStatus('default', funcObject)) == false) {
92+
throw `Function ${funcObject.FuncName} create/update failed`
93+
}
94+
9195
this.serverless.cli.log(`Rollback configure for function ${funcObject.FuncName}`)
9296
await func.updateConfiguration('default', oldFunc, funcObject)
9397

98+
if ((await func.checkStatus('default', funcObject)) == false) {
99+
throw `Function ${funcObject.FuncName} create/update failed`
100+
}
101+
94102
this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`)
95103
await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags)
96104

0 commit comments

Comments
 (0)