Skip to content

Commit

Permalink
每9分钟刷新一次Token
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobr committed Jun 29, 2024
1 parent 21a1b96 commit d1fc10c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions util/Task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def __init__(
conditions=lambda: self.createStatusResult is False,
)

# 上次刷新时间
self.lastTime = time()

# 关闭Transitions自带日志
logging.getLogger("transitions").setLevel(logging.CRITICAL)

Expand Down Expand Up @@ -203,7 +206,7 @@ def QueryTokenAction(self) -> None:
返回值: 0-成功, 1-风控, 2-未开票, 3-未知
"""
self.queryTokenResult = self.api.QueryToken()
self.threadTime = time()
self.lastTime = time()

# 顺路
if self.queryTokenResult == 0:
Expand Down Expand Up @@ -287,9 +290,8 @@ def Run(self) -> bool:

while self.state != "完成": # type: ignore
sleep(0.15)
if self.state in job: # type: ignore
self.trigger(job[self.state]) # type: ignore
else:
logger.warning("状态机异常!")
self.keep_running = False
self.trigger(job[self.state]) # type: ignore
if time() >= self.lastTime + 9 * 60:
logger.info("【刷新Token】已经9分钟没刷新Token了! 开始刷新")
self.to_获取Token() # type: ignore
return True

0 comments on commit d1fc10c

Please sign in to comment.