-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lambda): move reusable functions from handler to helper file
- Loading branch information
1 parent
c894486
commit 2b39f09
Showing
2 changed files
with
46 additions
and
40 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/artillery/lib/platform/aws-lambda/lambda-handler/helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { spawn } = require('node:child_process'); | ||
|
||
const sleep = async function (n) { | ||
return new Promise((resolve, _reject) => { | ||
setTimeout(function () { | ||
resolve(); | ||
}, n); | ||
}); | ||
}; | ||
|
||
async function runProcess(name, args, { env, log } = opts) { | ||
return new Promise((resolve, reject) => { | ||
const proc = spawn(name, args, { env }); | ||
let stdout = ''; | ||
let stderr = ''; | ||
|
||
proc.stdout.on('data', (data) => { | ||
if (log) { | ||
console.log(data.toString()); | ||
} | ||
stdout += data.toString(); | ||
}); | ||
|
||
proc.stderr.on('data', (data) => { | ||
if (log) { | ||
console.error(data.toString()); | ||
} | ||
|
||
stderr += data.toString(); | ||
}); | ||
|
||
proc.once('close', (code) => { | ||
resolve({ stdout, stderr, code }); | ||
}); | ||
|
||
proc.on('error', (err) => { | ||
resolve({ stdout, stderr, err }); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
runProcess, | ||
sleep | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters