| 715 | } |
| 716 | |
| 717 | export async function shutdownBuilder(match: BuildMatch): Promise<void> { |
| 718 | const ops: Promise<void>[] = []; |
| 719 | |
| 720 | if (match.buildProcess) { |
| 721 | const { pid } = match.buildProcess; |
| 722 | output.debug(`Killing builder sub-process with PID ${pid}`); |
| 723 | const killPromise = treeKill(pid!) |
| 724 | .then(() => { |
| 725 | output.debug(`Killed builder with PID ${pid}`); |
| 726 | }) |
| 727 | .catch((err: Error) => { |
| 728 | output.debug(`Failed to kill builder with PID ${pid}: ${err}`); |
| 729 | }); |
| 730 | ops.push(killPromise); |
| 731 | delete match.buildProcess; |
| 732 | } |
| 733 | |
| 734 | if (match.buildOutput) { |
| 735 | for (const asset of Object.values(match.buildOutput)) { |
| 736 | if (asset.type === 'Lambda' && asset.fn) { |
| 737 | output.debug(`Shutting down Lambda function`); |
| 738 | ops.push(asset.fn.destroy()); |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | await Promise.all(ops); |
| 744 | } |