perf:优化重新登录异常提醒逻辑
This commit is contained in:
父節點
99f3963d08
當前提交
e6c922b881
@ -1,6 +1,6 @@
|
|||||||
import {IJsonCourse} from "./types"
|
import {IJsonCourse} from "./types"
|
||||||
import {JsonCourseList} from "./poll"
|
import {JsonCourseList} from "./poll"
|
||||||
import {findJsonCourse} from "./includes"
|
import {findJsonCourse, getTimeNow} from "./includes"
|
||||||
import {appConfig} from "./config"
|
import {appConfig} from "./config"
|
||||||
import {scalarOptions} from "yaml"
|
import {scalarOptions} from "yaml"
|
||||||
import Str = scalarOptions.Str
|
import Str = scalarOptions.Str
|
||||||
@ -42,7 +42,7 @@ export async function health() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('[health]实时总退课人次:' + totalExitCount + '(' + shuffle(exitNames).slice(0, 3).join(',') + '等),总选课人次:'
|
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))
|
lastJsonCourseList = JSON.parse(JSON.stringify(JsonCourseList))
|
||||||
setTimeout(health, 60 * 1000)
|
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"
|
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'
|
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[] }>{
|
export const JsonCourseList = <{ bx: IJsonCourse[], xx: IJsonCourse[], rx: IJsonCourse[] }>{
|
||||||
bx: [],
|
bx: [],
|
||||||
@ -20,9 +21,8 @@ async function updateBx() {
|
|||||||
JsonCourseList.bx.push(...resp.data.aaData)
|
JsonCourseList.bx.push(...resp.data.aaData)
|
||||||
}
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
// console.log(_e)
|
|
||||||
await processError(_e as Error)
|
|
||||||
console.log('获取必修JsonList失败 at ' + getTimeNow())
|
console.log('获取必修JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ async function updateXx() {
|
|||||||
JsonCourseList.xx.push(...resp.data.aaData)
|
JsonCourseList.xx.push(...resp.data.aaData)
|
||||||
}
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
await processError(_e as Error)
|
|
||||||
console.log('获取限选JsonList失败 at ' + getTimeNow())
|
console.log('获取限选JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ async function updateRx() {
|
|||||||
JsonCourseList.rx.push(...resp.data.aaData)
|
JsonCourseList.rx.push(...resp.data.aaData)
|
||||||
}
|
}
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
await processError(_e as Error)
|
|
||||||
console.log('获取任选JsonList失败 at ' + getTimeNow())
|
console.log('获取任选JsonList失败 at ' + getTimeNow())
|
||||||
|
await processError(_e as Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +69,21 @@ export async function poll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processError(e: Error) {
|
async function processError(e: Error) {
|
||||||
errorCount++
|
currentErrorCount++
|
||||||
if (errorCount >= 30) {
|
if (currentErrorCount >= 30) {
|
||||||
logAndNotifyUser('[error]出现轮询error过多,进行重新登录。上一次异常信息:' + e.message)
|
console.log('[error]出现轮询error过多,进行重新登录。上一次异常信息:' + e.message)
|
||||||
await resetCookie()
|
try {
|
||||||
errorCount = 0
|
await resetCookie()
|
||||||
|
currentErrorCount = 0
|
||||||
|
} catch (_e) {
|
||||||
|
console.log('[error]重新登录失败')
|
||||||
|
}
|
||||||
|
if (totalErrorCount != -1) {
|
||||||
|
totalErrorCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (totalErrorCount >= 10) {
|
||||||
|
logAndNotifyUser('[error]重新登录失败次数过多,请检查 at ' + getTimeNow())
|
||||||
|
totalErrorCount = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
載入中…
x
新增問題並參考
Block a user