-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
childProcessHelper.js
50 lines (42 loc) · 1 KB
/
childProcessHelper.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
import InProcessRunner from '../in-process-runner/index.js'
// TODO handle this:
process.on('uncaughtException', (err) => {
const {
constructor: { name },
message,
stack,
} = err
process.send({
// process.send() can't serialize an Error object, so we help it out a bit
error: {
constructor: {
name,
},
message,
stack,
},
})
})
const [, , functionKey, handlerName, handlerPath] = process.argv
process.on('message', async (messageData) => {
const { context, event, allowCache, timeout } = messageData
// TODO we could probably cache this in the module scope?
const inProcessRunner = new InProcessRunner(
functionKey,
handlerPath,
handlerName,
process.env,
timeout,
allowCache,
)
let result
try {
result = await inProcessRunner.run(event, context)
} catch (err) {
// TODO logging
console.log(err)
throw err
}
// TODO check serializeability (contains function, symbol etc)
process.send(result)
})