Add market watch and match hub workflows
这个提交包含在:
@@ -9,7 +9,7 @@ import { appRouter } from "../routers";
|
||||
import { createContext } from "./context";
|
||||
import { registerMediaProxy } from "./mediaProxy";
|
||||
import { serveStatic } from "./static";
|
||||
import { createBackgroundTask, getAdminUserId, hasRecentBackgroundTaskOfType, seedAchievementDefinitions, seedAppSettings, seedTutorials, seedVisionReferenceImages } from "../db";
|
||||
import { createBackgroundTask, getAdminUserId, getAppSettingValue, hasRecentBackgroundTaskOfType, seedAchievementDefinitions, seedAppSettings, seedTutorials, seedVisionReferenceImages } from "../db";
|
||||
import { nanoid } from "nanoid";
|
||||
import { syncTutorialImages } from "../tutorialImages";
|
||||
|
||||
@@ -64,6 +64,32 @@ async function scheduleDailyNtrpRefresh() {
|
||||
});
|
||||
}
|
||||
|
||||
async function scheduleMarketWatchRefresh() {
|
||||
const intervalMinutes = Math.max(5, await getAppSettingValue("market_watch_refresh_interval_minutes", 30));
|
||||
const since = new Date(Date.now() - intervalMinutes * 60_000);
|
||||
const exists = await hasRecentBackgroundTaskOfType("market_watch_refresh", since);
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const adminUserId = await getAdminUserId();
|
||||
if (!adminUserId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const taskId = nanoid();
|
||||
await createBackgroundTask({
|
||||
id: taskId,
|
||||
userId: adminUserId,
|
||||
type: "market_watch_refresh",
|
||||
title: "全网球拍行情刷新",
|
||||
message: "系统已自动创建球拍行情刷新任务",
|
||||
payload: { scope: "all_users", trigger: "scheduler" },
|
||||
progress: 0,
|
||||
maxAttempts: 3,
|
||||
});
|
||||
}
|
||||
|
||||
function isPortAvailable(port: number): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
const server = net.createServer();
|
||||
@@ -129,6 +155,9 @@ async function startServer() {
|
||||
void scheduleDailyNtrpRefresh().catch((error) => {
|
||||
console.error("[scheduler] failed to schedule NTRP refresh", error);
|
||||
});
|
||||
void scheduleMarketWatchRefresh().catch((error) => {
|
||||
console.error("[scheduler] failed to schedule market refresh", error);
|
||||
});
|
||||
}, 60_000);
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户