Commit 1eb9bca5 by Haohao Jiang

feat: trigger processDetect if isMonday11AM OR should_run_tasks checked in redis

parent af7cd467
import { spawn } from "bun";
import Redis from "ioredis";
// 任务执行入口,自动设置 SLACK_WEBHOOK 并依次运行 gsheet、gsheet:ai 和 notify-slack
async function main() {
async function processDetect() {
const env = {
...process.env
};
......@@ -44,6 +45,37 @@ async function main() {
});
}
function isMonday11AM() {
const now = new Date();
return now.getDay() === 1 && now.getHours() === 11;
}
async function main() {
const redis = new Redis(Bun.env.REDIS_URL);
const shouldRun = await redis.get("falcon:should_run_tasks");
if (shouldRun === "true") {
await processDetect();
await redis.del("falcon:should_run_tasks");
console.log("should_run_tasks 执行完毕,已清理 redis key。");
} else if (isMonday11AM()) {
const mondayKey = "falcon:monday_11am_executed";
const alreadyExecuted = await redis.get(mondayKey);
if (alreadyExecuted) {
console.log("本周一11点任务已执行,跳过。");
} else {
await processDetect();
// 设置标记,24小时后自动过期
await redis.set(mondayKey, "true", "EX", 60 * 60 * 24);
console.log("定时任务触发,已执行 main 逻辑,并设置本周标记。");
}
} else {
console.log("should_run_tasks 不是 'true',且不是定时任务,跳过。");
}
await redis.quit();
}
// 调用入口
main().catch(err => {
console.error(err);
......
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