- 外围功能模块(补字幕、原站视图、桌面模式、网页搜索、MCP、定时任务)声明 manifest,与 FEATURES 一一对应; 系统提示「能力地图」末尾列出外围功能(没有开关,能力只列本次可用的) - 补字幕:订阅 organization.finished(认出值得补字幕的整理,自动补字幕还没做,不建任务), 写入字幕后在同一事务发 subtitle.written;原有行为不变 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { featureManifest } from "@umt/contracts";
|
|
import type { ServerContext, ServerModule } from "../types.ts";
|
|
import { builtinAgentCheckDefs } from "./agent-checks.ts";
|
|
import { registerScheduleCapabilities } from "./capabilities.ts";
|
|
import { registerScheduledJob, scheduleRegistry } from "./registry.ts";
|
|
import { registerScheduleRoutes } from "./routes.ts";
|
|
import { Scheduler, type SchedulerOptions } from "./scheduler.ts";
|
|
|
|
export type { JobRunContext, JobRunResult, ScheduledJobDef, ScheduledJobDefaults } from "./registry.ts";
|
|
export { registerScheduledJob, scheduleRegistry } from "./registry.ts";
|
|
|
|
/**
|
|
* W7-C 定时任务统一注册表 + 看板(docs/runbook/schedules.md):
|
|
* 各模块 start() 用 registerScheduledJob 登记周期任务;本模块在 io worker 上起唯一调度器(PG 咨询锁)按表驱动,
|
|
* 并登记内置 Agent 巡检模板(默认关闭)与备份占位。看板 API 见 routes.ts(全部只接受控制台会话)。
|
|
* 须放在 SERVER_MODULES 末尾:start 时其它模块已登记完(之后再登记的也会在下一轮同步)。
|
|
*/
|
|
export interface SchedulesModuleOptions {
|
|
scheduler?: SchedulerOptions;
|
|
/** 缺省 true;测试可关掉内置巡检 */
|
|
builtinChecks?: boolean;
|
|
}
|
|
|
|
export function createSchedulesModule(opts: SchedulesModuleOptions = {}): ServerModule & {
|
|
scheduler(): Scheduler | null;
|
|
} {
|
|
let scheduler: Scheduler | null = null;
|
|
return {
|
|
name: "schedules",
|
|
manifest: featureManifest("schedules"),
|
|
scheduler: () => scheduler,
|
|
registerRoutes(app, ctx) {
|
|
registerScheduleRoutes(app, ctx, () => scheduleRegistry(ctx));
|
|
},
|
|
registerTasks() {},
|
|
registerCapabilities(registry, ctx) {
|
|
registerScheduleCapabilities(registry, ctx);
|
|
},
|
|
start(ctx: ServerContext) {
|
|
if (opts.builtinChecks !== false) for (const def of builtinAgentCheckDefs(ctx)) registerScheduledJob(ctx, def);
|
|
// 备份目前由宿主机 scripts/backup.sh(cron / 手动)执行,这里只占位,看板上显示"未配置"
|
|
registerScheduledJob(ctx, {
|
|
key: "maintain.backup",
|
|
defaults: {
|
|
name: "备份",
|
|
description: "数据库与数据目录备份,目前在服务器上用命令执行",
|
|
group: "maintain",
|
|
schedule: { type: "cron", cron: "30 3 * * *" },
|
|
enabled: false,
|
|
available: false,
|
|
},
|
|
run: async () => ({ status: "skipped", summary: "未配置" }),
|
|
});
|
|
scheduler = new Scheduler(ctx, scheduleRegistry(ctx), opts.scheduler);
|
|
scheduler.start();
|
|
},
|
|
async stop() {
|
|
await scheduler?.stop();
|
|
scheduler = null;
|
|
},
|
|
};
|
|
}
|
|
|
|
export const schedulesModule = createSchedulesModule();
|