forked from rujor/false
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (33 loc) · 1.1 KB
/
index.js
File metadata and controls
35 lines (33 loc) · 1.1 KB
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
const { execFile } = require( 'child_process' );
/*
To enable the initializer feature (https://help.aliyun.com/document_detail/156876.html)
please implement the initializer function as below:
exports.initializer = (context, callback) => {
console.log('initializing');
callback(null, '');
};
*/
exports.handler = async ( event, context, callback ) => {
var eventObj;
eventObj = JSON.parse( event ).payload
console.log( `开始执行: 参数为:${ eventObj }` )
const tasks = [];
console.log( `run script:${ eventObj }` )
const name = './' + eventObj + '.js'
tasks[0] = new Promise( ( resolve ) => {
const child = execFile( process.execPath, [name] )
child.stdout.on( 'data', function ( data ) {
console.log( data )
} )
child.stderr.on( 'data', function ( data ) {
console.error( data )
} )
child.on( 'close', function ( code ) {
console.log( `${ eventObj } finished` )
delete child
resolve()
} )
} )
await Promise.all( tasks )
callback( null, "执行完毕" )
}