refactor(AWS Local Invocation): Rely on observable spawn

It's to better debug observed issues
This commit is contained in:
Mariusz Nowak 2022-04-25 14:26:46 +02:00 committed by Mariusz Nowak
parent 6cbc83aff0
commit 6d9749699d

View File

@ -605,28 +605,25 @@ class AwsInvokeLocal {
const wrapperPath = await this.resolveRuntimeWrapperPath('invoke.py');
return new Promise((resolve, reject) => {
const python = spawn(runtime.split('.')[0], ['-u', wrapperPath, handlerPath, handlerName], {
env: process.env,
});
return new Promise((resolve) => {
const python = spawnExt(
runtime.split('.')[0],
['-u', wrapperPath, handlerPath, handlerName],
{
env: process.env,
}
);
python.stdout.on('data', (buf) => {
writeText(buf.toString());
});
python.stderr.on('data', (buf) => {
writeText(buf.toString());
});
python.on('close', () => resolve());
let isRejected = false;
python.on('error', (error) => {
isRejected = true;
reject(error);
});
process.nextTick(() => {
if (isRejected) return; // Runtime not available
python.stdin.write(input);
python.stdin.end();
});
python.child.stdin.write(input);
python.child.stdin.end();
resolve(python);
});
}