Files
ranking/starter.ts
2025-11-12 02:58:36 +09:00

60 lines
1.7 KiB
TypeScript

import schedule from "node-schedule";
import { exec } from "node:child_process";
console.log("start ...");
function runTsFile(filePath: string): Promise<void> {
return new Promise((resolve, reject) => {
console.log(`Starting: ${filePath}`);
exec(`bun run ${filePath}`, (error, stdout, stderr) => {
if (error) {
console.error(`Execution error: ${error.message}`);
reject(error);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
}
console.log(`Output: ${stdout}`);
console.log(`Completed: ${filePath}`);
resolve();
});
});
}
// 10시에 실행 - fetch-articles.ts 실행 후 app.ts 실행
schedule.scheduleJob("0 0 10 * * *", async () => {
console.log("Running parserLandList.ts at 10:00 AM");
try {
await runTsFile("./fetch-articles.ts");
// fetch-articles.ts 완료 후 app.ts 실행
await runTsFile("./fetch-detailAddress.ts");
} catch (error) {
console.error("Error in scheduled job:", error);
}
});
// 11시에 실행
schedule.scheduleJob("0 11 * * *", () => {
console.log("Running app.ts at 11 AM");
runTsFile("./app.ts");
});
// 15시에 실행 - fetch-articles.ts 실행 후 app.ts 실행
schedule.scheduleJob("0 0 15 * * *", async () => {
console.log("Running parserLandList.ts at 3:00 PM");
try {
await runTsFile("./fetch-articles.ts");
// fetch-articles.ts 완료 후 app.ts 실행
await runTsFile("./fetch-detailAddress.ts");
} catch (error) {
console.error("Error in scheduled job:", error);
}
});
// 16시에 실행
schedule.scheduleJob("0 16 * * *", () => {
console.log("Running app.ts at 4 PM");
runTsFile("./app.ts");
});