-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobless_handler.js
57 lines (51 loc) · 1.18 KB
/
jobless_handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const main = require('./build/main') // 入口
const config = require("./config") // 配置
main.init(config) // 初始化
/**
* 判断对象是否 Promise 对象
*
* @param {*} value
* @returns
*/
function isPromise(value) {
return value && Object.prototype.toString.call(value) === "[object Promise]";
}
exports.handler = async (event, context) => {
try {
var result = main.main(event, context, config);
if (isPromise(result)) {
result = await result.then()
}
if (typeof result == "object")
return JSON.stringify({
"result": "COMPLETE",
"variables": result
})
if (result == null)
return JSON.stringify({
"result": "COMPLETE",
"variables": null
})
return JSON.stringify({
"result": "COMPLETE",
"variables": {
"result": result
}
})
} catch (e) {
console.error(e);
if (e.type == "FAIL") {
return JSON.stringify({
"result": "FAIL",
"errorMessage": e.message,
"retires": e.retires
})
}
return JSON.stringify({
"result": "ERROR",
"errorCode": e.code || 0,
"errorMessage": e.message
})
}
};