Commit 515f1e5e by Lin Wang

fix: change spawn to spawnSync

parent 3acf7279
import { spawn } from "bun";
import { spawnSync } from "bun";
import Redis from "ioredis";
// 任务执行入口,自动设置 SLACK_WEBHOOK 并依次运行 gsheet、gsheet:ai 和 notify-slack
......@@ -38,24 +38,32 @@ async function main() {
// 运行 bun run detect
console.log(`[${task_trigger}] 开始执行 detect`);
const detectProcess = spawn({
const detectResult = spawnSync({
cmd: ["bun", "run", "detect"],
env,
stdout: "inherit",
stderr: "inherit"
});
await detectProcess.exited;
if (detectResult.exitCode !== 0) {
console.error(`[${task_trigger}] detect 执行失败,退出码: ${detectResult.exitCode}`);
await redis.quit();
process.exit(1);
}
console.log(`[${task_trigger}] detect 执行完成`);
// 运行 bun run task:gsheet
console.log(`[${task_trigger}] 开始执行 task:gsheet`);
const gsheetProcess = spawn({
const gsheetResult = spawnSync({
cmd: ["bun", "run", "task:gsheet"],
env,
stdout: "inherit",
stderr: "inherit"
});
await gsheetProcess.exited;
if (gsheetResult.exitCode !== 0) {
console.error(`[${task_trigger}] task:gsheet 执行失败,退出码: ${gsheetResult.exitCode}`);
await redis.quit();
process.exit(1);
}
console.log(`[${task_trigger}] task:gsheet 执行完成`);
// 延迟执行 task:gsheet:ai 避免 Google Sheet 限流
......@@ -65,24 +73,32 @@ async function main() {
// 运行 bun run task:gsheet:ai
console.log(`[${task_trigger}] 开始执行 task:gsheet:ai`);
const gsheetAiProcess = spawn({
const gsheetAiResult = spawnSync({
cmd: ["bun", "run", "task:gsheet:ai"],
env,
stdout: "inherit",
stderr: "inherit"
});
await gsheetAiProcess.exited;
if (gsheetAiResult.exitCode !== 0) {
console.error(`[${task_trigger}] task:gsheet:ai 执行失败,退出码: ${gsheetAiResult.exitCode}`);
await redis.quit();
process.exit(1);
}
console.log(`[${task_trigger}] task:gsheet:ai 执行完成`);
// 运行 bun run notify-slack
console.log(`[${task_trigger}] 开始执行 notify-slack`);
const notifySlackProcess = spawn({
const notifySlackResult = spawnSync({
cmd: ["bun", "run", "notify-slack"],
env,
stdout: "inherit",
stderr: "inherit"
});
await notifySlackProcess.exited;
if (notifySlackResult.exitCode !== 0) {
console.error(`[${task_trigger}] notify-slack 执行失败,退出码: ${notifySlackResult.exitCode}`);
await redis.quit();
process.exit(1);
}
console.log(`[${task_trigger}] notify-slack 执行完成`);
if (task_trigger === "should_run_tasks") {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment