Skip to content

Commit

Permalink
๐Ÿ”จ Fix: lambda tmp puppeteer ํ”„๋กœํŒŒ์ผ ์‚ญ์ œ์ฝ”๋“œ ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
#
  • Loading branch information
qilip committed Nov 14, 2023
1 parent bcc40a1 commit 0c7b0b4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exec } from 'child_process';
import {
Status,
changeDocStatus,
Expand Down Expand Up @@ -34,6 +35,9 @@ export const handler = async (event, context) => {
// ํ•ด๋‹น Doc์˜ ์ƒํƒœ๋ฅผ ์ฒ˜๋ฆฌ์ค‘์œผ๋กœ ๋ณ€๊ฒฝ
await changeDocStatus(documentId, Status.SCRAPE_PROCESSING);

// ์ด์ „ puppeteer ํฌ๋กœ๋ฏธ์›€ ํ”„๋กœํŒŒ์ผ ์‚ญ์ œ
cleanTmpDirectory();

try {
// lambda timeout 10์ดˆ ์ „์œผ๋กœ ์ œํ•œ์‹œ๊ฐ„ ์„ค์ •
await promiseTimeout(
Expand Down Expand Up @@ -98,3 +102,18 @@ const job = async (doc: any, documentId: number) => {
throw e;
}
};

const cleanTmpDirectory = () => {
const command = 'find /tmp -name "puppeteer_dev*" -type d | xargs rm -rf';
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`cleanTmp exec error: ${error}`);
return;
}
if (stderr) {
console.error(`cleanTmp stderr: ${stderr}`);
return;
}
console.log(`cleanTmp stdout: ${stdout}`);
});
};

0 comments on commit 0c7b0b4

Please sign in to comment.