diff --git a/bun.lockb b/bun.lockb index 4e53bdf..0746628 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index 59599b6..47d4d0f 100644 --- a/index.ts +++ b/index.ts @@ -1,30 +1,10 @@ -import { scheduleJob } from "node-schedule"; -import managePipeline from "./controllers/managePipeLine"; -import manageProject from "./controllers/manageProject"; -import manageUser from "./controllers/manageUser"; import manageRobot from "./controllers/manageRobot"; +import initSchedule from "./schedule"; -const main = async () => { - const fullProjList = await manageProject.getFullProjList(); - const fullPipelineList = await Promise.all( - fullProjList.map((v) => managePipeline.getFullPipelineList(v)) - ); - const fullUserMap = await manageUser.getFullUserMap(fullPipelineList); - const fullProjectMap = await manageProject.getFullProjectMap(fullProjList); - await managePipeline.insertFullPipelineList( - fullPipelineList, - fullUserMap, - fullProjectMap - ); -}; +// 启动定时任务 +initSchedule(); -main(); - -scheduleJob("*/15 * * * *", main); - -scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron); - -Bun.serve({ +const server = Bun.serve({ async fetch(req) { const url = new URL(req.url); if (url.pathname === "/ci") { @@ -43,3 +23,5 @@ Bun.serve({ }, port: 3000, }); + +console.log(`Listening on ${server.hostname}:${server.port}`); \ No newline at end of file diff --git a/schedule/index.ts b/schedule/index.ts new file mode 100644 index 0000000..442646b --- /dev/null +++ b/schedule/index.ts @@ -0,0 +1,14 @@ +import { scheduleJob } from "node-schedule"; +import manageRobot from "../controllers/manageRobot"; +import syncPipLine from "./syncPipLine"; + +const initSchedule = async () => { + // 每天十点钟发送CI报告 + scheduleJob("0 10 * * *", manageRobot.sendCIReportByCron); + // 每15分钟同步一次CI数据 + scheduleJob("*/15 * * * *", syncPipLine); + // 立即同步一次 + syncPipLine(); +} + +export default initSchedule; \ No newline at end of file diff --git a/schedule/syncPipLine.ts b/schedule/syncPipLine.ts new file mode 100644 index 0000000..c4e6245 --- /dev/null +++ b/schedule/syncPipLine.ts @@ -0,0 +1,19 @@ +import managePipeline from "../controllers/managePipeLine"; +import manageProject from "../controllers/manageProject"; +import manageUser from "../controllers/manageUser"; + +const syncPipLine = async () => { + const fullProjList = await manageProject.getFullProjList(); + const fullPipelineList = await Promise.all( + fullProjList.map((v) => managePipeline.getFullPipelineList(v)) + ); + const fullUserMap = await manageUser.getFullUserMap(fullPipelineList); + const fullProjectMap = await manageProject.getFullProjectMap(fullProjList); + await managePipeline.insertFullPipelineList( + fullPipelineList, + fullUserMap, + fullProjectMap + ); +}; + +export default syncPipLine; \ No newline at end of file