feat: 关闭定时任务
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 47s

This commit is contained in:
zhaoyingbo 2024-08-09 02:24:53 +00:00
parent 275160f3ae
commit d748879b4c
3 changed files with 18 additions and 13 deletions

View File

@ -1,11 +1,11 @@
import { manageCIMonitorReq } from "./routes/ci"
import { manageGitlabEventReq } from "./routes/event"
import initSchedule from "./schedule"
// import initSchedule from "./schedule"
import netTool from "./service/netTool"
import { makeCheckPathTool } from "./utils/pathTools"
// 启动定时任务
initSchedule()
// initSchedule()
const PREFIX = "/gitlab_monitor"

View File

@ -1,6 +1,7 @@
import { scheduleJob } from "node-schedule"
import manageRobot from "../controllers/manageRobot"
import monitorJob from "./monitorJob"
import syncPipeLine from "./syncPipeLine"
const initSchedule = async () => {
@ -9,11 +10,11 @@ const initSchedule = async () => {
// 每15分钟同步一次CI数据
scheduleJob("*/15 * * * *", syncPipeLine)
// // 每30秒执行一次监控任务
// scheduleJob("*30 * * * * *", monitorJob)
scheduleJob("*30 * * * * *", monitorJob)
// 立即同步一次
syncPipeLine()
// // 立即执行一次监控任务
// monitorJob()
monitorJob()
}
export default initSchedule

View File

@ -49,16 +49,20 @@ const doMonitor = async (monitor: DB.Monitor): Promise<void> => {
* @returns {Promise<void>}
* @description 24
*/
const removeOverTimeMonitor = async (): Promise<void> => {
const fullMonitorList = await db.monitor.getFullList()
const removeOverTimeMonitor = async (
fullMonitorList: DB.Monitor[]
): Promise<void> => {
const now = Date.now()
const limit = pLimit(5)
await Promise.all(
fullMonitorList.map(async (monitor) => {
const createdAtTimestamp = new Date(monitor.created_at).getTime()
if (now - createdAtTimestamp > 24 * 60 * 60 * 1000) {
await db.monitor.del(monitor.id)
}
})
fullMonitorList.map((monitor) =>
limit(async () => {
const createdAtTimestamp = new Date(monitor.created_at).getTime()
if (now - createdAtTimestamp > 24 * 60 * 60 * 1000) {
await db.monitor.del(monitor.id)
}
})
)
)
}
@ -70,7 +74,7 @@ const monitorJob = async (): Promise<void> => {
// 获取全部监控项
const fullMonitorList = await db.monitor.getFullList()
// 移除超过24小时的监控项
removeOverTimeMonitor()
removeOverTimeMonitor(fullMonitorList)
if (fullMonitorList.length === 0) return
// 并发限制
const limit = pLimit(3)