Skip to content

Commit

Permalink
fix: 解决无限回滚问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sz134055 authored and Samueli924 committed Oct 21, 2024
1 parent 3f77005 commit 79dce0e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@ def init_config():
else:
return (args.username, args.password, args.list.split(",") if args.list else None, int(args.speed) if args.speed else 1,None)

class RollBackManager:
def __init__(self) -> None:
self.rollback_times = 0
self.rollback_id = ""
def reset_times(self,id:str) -> int:
if id == self.rollback_id:
self.rollback_times = 0
def add_times(self,id:str) -> None:
if id == self.rollback_id and self.rollback_times == 3:
raise Exception("回滚次数已达3次,请手动检查学习通任务点完成情况")
elif id != self.rollback_id:
# 新job
self.rollback_id = id
self.rollback_times = 1
else:
self.rollback_times += 1


if __name__ == '__main__':
try:
# 避免异常的无限回滚
ROLLBACK_TIMES = 0 # 回滚计数器

RB = RollBackManager()
# 初始化登录信息
username, password, course_list, speed,tiku_config= init_config()
# 规范化播放速度的输入值
Expand Down Expand Up @@ -98,13 +114,11 @@ def init_config():
# 未启用题库或未开启题库提交,章节检测未完成会导致无法开始下一章,直接退出
logger.error(f"章节未开启,可能由于上一章节的章节检测未完成,请手动完成并提交再重试,或者开启题库并启用提交")
break
if ROLLBACK_TIMES == 3:
raise Exception("回滚次数已达3次,请手动检查学习通任务点完成情况")
ROLLBACK_TIMES +=1
RB.add_times(point["id"])
continue

# 正常获取,重置回滚计数器
ROLLBACK_TIMES = 0
# 正常获取,尝试重置回滚次数
RB.reset_times(point["id"])

# 可能存在章节无任何内容的情况
if not jobs:
Expand Down

0 comments on commit 79dce0e

Please sign in to comment.