From 4c109a006f06658fdbd6cbbb50a0b391085746bf Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Fri, 28 Jun 2024 10:15:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=BD=E8=B1=A1=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bun.lockb | Bin 6436 -> 6436 bytes index.ts | 30 ++++++------------------------ schedule/index.ts | 14 ++++++++++++++ schedule/syncPipLine.ts | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 schedule/index.ts create mode 100644 schedule/syncPipLine.ts diff --git a/bun.lockb b/bun.lockb index 4e53bdfd53a3b9781cbd3bbc22a3e65237a32b97..0746628b4bdd8fcc3e8811ebefd8a32c959afbf0 100755 GIT binary patch delta 114 zcmZ2tw8Usb1>%inSFsa7@5@`dI_rRnXCrG3ZOg;mXc3dElX<+glSNP-xMs}WM^$ZL! hcT6s16k%iolEPFajW@e;$1`p|z!Si@Ihg+ { - 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