This commit is contained in:
parent
5903c7ee94
commit
50121dc073
@ -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<Response> => {
|
||||
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...")
|
||||
}
|
||||
|
@ -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()
|
||||
// 立即执行一次监控任务
|
||||
|
@ -69,6 +69,8 @@ const removeOverTimeMonitor = async (): Promise<void> => {
|
||||
const monitorJob = async (): Promise<void> => {
|
||||
// 获取全部监控项
|
||||
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<void> => {
|
||||
await Promise.all(
|
||||
fullMonitorList.map((monitor) => limit(() => doMonitor(monitor)))
|
||||
)
|
||||
// 移除超过24小时的监控项
|
||||
await removeOverTimeMonitor()
|
||||
}
|
||||
|
||||
export default monitorJob
|
||||
|
3
script/mr/index.ts
Normal file
3
script/mr/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import service from "../../service"
|
||||
|
||||
service.gitlab.MergeRequests.allDiffVersions(1, 1).then(console.log)
|
12
test/ci.test.ts
Normal file
12
test/ci.test.ts
Normal file
@ -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..."))
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user