diff --git a/routes/ci/index.ts b/routes/ci/index.ts index 9cd1727..6a1acef 100644 --- a/routes/ci/index.ts +++ b/routes/ci/index.ts @@ -6,10 +6,10 @@ import netTool from "../../service/netTool" * @param {Request} req - 请求对象。 * @returns {Response} - 响应对象。 */ -export const manageCIMonitorReq = (req: Request): Response => { +export const manageCIMonitorReq = async (req: Request): Promise => { const url = new URL(req.url) const chat_id = url.searchParams.get("chat_id") if (!chat_id) return netTool.badRequest("chat_id is required!") - manageRobot.sendCIReportByChatId(chat_id) + await manageRobot.sendCIReportByChatId(chat_id) return netTool.ok("reporting...") } diff --git a/schedule/index.ts b/schedule/index.ts index adbfa25..25cb4e6 100644 --- a/schedule/index.ts +++ b/schedule/index.ts @@ -9,8 +9,8 @@ const initSchedule = async () => { scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron) // 每15分钟同步一次CI数据 scheduleJob("*/15 * * * *", syncPipeLine) - // 每10秒执行一次监控任务 - scheduleJob("*/10 * * * * *", monitorJob) + // 每30秒执行一次监控任务 + scheduleJob("*30 * * * * *", monitorJob) // 立即同步一次 syncPipeLine() // 立即执行一次监控任务 diff --git a/schedule/monitorJob.ts b/schedule/monitorJob.ts index e749c4e..aa51699 100644 --- a/schedule/monitorJob.ts +++ b/schedule/monitorJob.ts @@ -69,6 +69,8 @@ const removeOverTimeMonitor = async (): Promise => { const monitorJob = async (): Promise => { // 获取全部监控项 const fullMonitorList = await db.monitor.getFullList() + // 移除超过24小时的监控项 + removeOverTimeMonitor() if (fullMonitorList.length === 0) return // 并发限制 const limit = pLimit(3) @@ -76,8 +78,6 @@ const monitorJob = async (): Promise => { await Promise.all( fullMonitorList.map((monitor) => limit(() => doMonitor(monitor))) ) - // 移除超过24小时的监控项 - await removeOverTimeMonitor() } export default monitorJob diff --git a/script/mr/index.ts b/script/mr/index.ts new file mode 100644 index 0000000..065ad7f --- /dev/null +++ b/script/mr/index.ts @@ -0,0 +1,3 @@ +import service from "../../service" + +service.gitlab.MergeRequests.allDiffVersions(1, 1).then(console.log) diff --git a/test/ci.test.ts b/test/ci.test.ts new file mode 100644 index 0000000..e2f61bb --- /dev/null +++ b/test/ci.test.ts @@ -0,0 +1,12 @@ +import { expect, test } from "bun:test" + +import { manageCIMonitorReq } from "../routes/ci" +import netTool from "../service/netTool" + +test("manageCIMonitorReq", async () => { + const req = new Request( + "https://ci-monitor.xiaomiwh.cn/gitlab/ci?chat_id=oc_8c789ce8f4ecc6695bb63ca6ec4c61ea" + ) + const res = await manageCIMonitorReq(req) + expect(res).toEqual(netTool.ok("reporting...")) +})