This commit is contained in:
parent
275160f3ae
commit
d748879b4c
4
index.ts
4
index.ts
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user