forked from juzheng/sdu-course-bot
		
	feat:程序health监控
This commit is contained in:
		
							
								
								
									
										37
									
								
								src/health.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/health.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| import {IJsonCourse} from "./types" | ||||
| import {JsonCourseList} from "./poll" | ||||
| import {findJsonCourse} from "./includes" | ||||
| import {appConfig} from "./config" | ||||
|  | ||||
| let lastJsonCourseList: { bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] } | ||||
| let firstRunHealth = true | ||||
|  | ||||
| export async function health() { | ||||
|     let totalAcquireCount = 0 | ||||
|     let totalExitCount = 0 | ||||
|     if (firstRunHealth) { | ||||
|         console.log('[health]程序health监控启动完毕') | ||||
|         firstRunHealth = false | ||||
|     } else { | ||||
|         for (let channel of appConfig.channels) { | ||||
|             for (let lastCourse of lastJsonCourseList[channel]) { | ||||
|                 let currentCourse = findJsonCourse({ | ||||
|                     kch: lastCourse.kch, | ||||
|                     kxh: parseInt(lastCourse.kxh), | ||||
|                     channel: channel | ||||
|                 }) | ||||
|                 if (currentCourse == undefined) { | ||||
|                     continue | ||||
|                 } | ||||
|                 if (parseInt(currentCourse.syrs) > parseInt(lastCourse.syrs)) { | ||||
|                     totalExitCount += parseInt(currentCourse.syrs) - parseInt(lastCourse.syrs) | ||||
|                 } else { | ||||
|                     totalAcquireCount += parseInt(lastCourse.syrs) - parseInt(currentCourse.syrs) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         console.log('[health]实时总退课人次:' + totalExitCount + ',总选课人次:' + totalAcquireCount) | ||||
|     } | ||||
|     lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList)) | ||||
|     setTimeout(health, 60 * 1000) | ||||
| } | ||||
| @@ -2,6 +2,7 @@ import {JsonCourseList, poll} from "./poll" | ||||
| import {appConfig} from "./config" | ||||
| import {acquireProcess, monitProcess, replaceProcess} from "./actions" | ||||
| import {sleep} from "./includes" | ||||
| import {health} from "./health" | ||||
|  | ||||
| async function start() { | ||||
|     console.log('开始启动轮询进程') | ||||
| @@ -30,6 +31,7 @@ async function start() { | ||||
|         replaceProcess(appConfig.replace.list, appConfig.replace.exit) | ||||
|     } | ||||
|     console.log('用户进程启动完毕') | ||||
|     health() | ||||
| } | ||||
|  | ||||
| start() | ||||
|   | ||||
| @@ -23,8 +23,8 @@ async function test() { | ||||
|     let resp = await sduAxios.post('/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=', reqBody) | ||||
|     fs.writeFileSync('arr.json', JSON.stringify(resp.data.aaData, null, 2)) | ||||
|     let courseList: IJsonCourse[] = resp.data.aaData | ||||
|     courseList = courseList.filter(single => (single.kcmc.includes('稷下创新') || single.kcmc.includes('齐鲁创业')) | ||||
|         && single.xqmc == '软件园校区') | ||||
|     courseList = courseList.filter(single => single.kcmc.includes('稷下创新') | ||||
|         && single.xf >= 2) | ||||
|     for (let course of courseList) { | ||||
|         console.log(course.kcmc + ' ' + course.kch + ' ' + course.kxh + ' ' + course.syrs + ' ' + course.xf) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user