forked from juzheng/sdu-course-bot
		
	perf:优化重新登录异常提醒逻辑
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| import {IJsonCourse} from "./types" | ||||
| import {JsonCourseList} from "./poll" | ||||
| import {findJsonCourse} from "./includes" | ||||
| import {findJsonCourse, getTimeNow} from "./includes" | ||||
| import {appConfig} from "./config" | ||||
| import {scalarOptions} from "yaml" | ||||
| import Str = scalarOptions.Str | ||||
| @@ -42,7 +42,7 @@ export async function health() { | ||||
|             } | ||||
|         } | ||||
|         console.log('[health]实时总退课人次:' + totalExitCount + '(' + shuffle(exitNames).slice(0, 3).join(',') + '等),总选课人次:' | ||||
|             + totalAcquireCount + '(' + shuffle(acquireNames).slice(0, 3).join(',') + '等)') | ||||
|             + totalAcquireCount + '(' + shuffle(acquireNames).slice(0, 3).join(',') + '等) at ' + getTimeNow()) | ||||
|     } | ||||
|     lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList)) | ||||
|     setTimeout(health, 60 * 1000) | ||||
|   | ||||
							
								
								
									
										31
									
								
								src/poll.ts
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/poll.ts
									
									
									
									
									
								
							| @@ -4,7 +4,8 @@ import {appConfig} from "./config" | ||||
| import * as qs from "qs" | ||||
|  | ||||
| export let reqBody = 'sEcho=1&iColumns=15&sColumns=&iDisplayStart=0&iDisplayLength=2000&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=jkfs&mDataProp_4=xmmc&mDataProp_5=fzmc&mDataProp_6=ktmc&mDataProp_7=xf&mDataProp_8=skls&mDataProp_9=sksj&mDataProp_10=skdd&mDataProp_11=xqmc&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=czOper' | ||||
| let errorCount = 0 | ||||
| let currentErrorCount = 0 | ||||
| let totalErrorCount = 0 | ||||
|  | ||||
| export const JsonCourseList = <{ bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }>{ | ||||
|     bx: [], | ||||
| @@ -20,9 +21,8 @@ async function updateBx() { | ||||
|             JsonCourseList.bx.push(...resp.data.aaData) | ||||
|         } | ||||
|     } catch (_e) { | ||||
|         // console.log(_e) | ||||
|         await processError(_e as Error) | ||||
|         console.log('获取必修JsonList失败 at ' + getTimeNow()) | ||||
|         await processError(_e as Error) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -34,8 +34,8 @@ async function updateXx() { | ||||
|             JsonCourseList.xx.push(...resp.data.aaData) | ||||
|         } | ||||
|     } catch (_e) { | ||||
|         await processError(_e as Error) | ||||
|         console.log('获取限选JsonList失败 at ' + getTimeNow()) | ||||
|         await processError(_e as Error) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -47,8 +47,8 @@ async function updateRx() { | ||||
|             JsonCourseList.rx.push(...resp.data.aaData) | ||||
|         } | ||||
|     } catch (_e) { | ||||
|         await processError(_e as Error) | ||||
|         console.log('获取任选JsonList失败 at ' + getTimeNow()) | ||||
|         await processError(_e as Error) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -69,10 +69,21 @@ export async function poll() { | ||||
| } | ||||
|  | ||||
| async function processError(e: Error) { | ||||
|     errorCount++ | ||||
|     if (errorCount >= 30) { | ||||
|         logAndNotifyUser('[error]出现轮询error过多,进行重新登录。上一次异常信息:' + e.message) | ||||
|         await resetCookie() | ||||
|         errorCount = 0 | ||||
|     currentErrorCount++ | ||||
|     if (currentErrorCount >= 30) { | ||||
|         console.log('[error]出现轮询error过多,进行重新登录。上一次异常信息:' + e.message) | ||||
|         try { | ||||
|             await resetCookie() | ||||
|             currentErrorCount = 0 | ||||
|         } catch (_e) { | ||||
|             console.log('[error]重新登录失败') | ||||
|         } | ||||
|         if (totalErrorCount != -1) { | ||||
|             totalErrorCount++ | ||||
|         } | ||||
|     } | ||||
|     if (totalErrorCount >= 10) { | ||||
|         logAndNotifyUser('[error]重新登录失败次数过多,请检查 at ' + getTimeNow()) | ||||
|         totalErrorCount = -1 | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user