fix: 任务开始后显示已开启和学时刷新倒计时
This commit is contained in:
@@ -131,6 +131,8 @@ def _set_user_status(employee_id: str, **kw: object) -> None:
|
||||
users = _status.setdefault("users", {})
|
||||
info = users.setdefault(employee_id, {})
|
||||
info.update(kw)
|
||||
if kw.get("state") in ("已停止", "已学完", "学习失败", "会话失效", "已达标"):
|
||||
info.pop("hours_refresh_at", None)
|
||||
info["month"] = str(kw["month"]) if "month" in kw else month_key()
|
||||
_status["updated_at"] = datetime.now(timezone.utc).isoformat()
|
||||
_notify(employee_id)
|
||||
@@ -762,6 +764,7 @@ class HoursWatcher:
|
||||
|
||||
async def ticker(self, global_stop: asyncio.Event) -> None:
|
||||
while not global_stop.is_set() and not self.user_stop.is_set():
|
||||
_set_user_status(self.employee_id, hours_refresh_at=time.time() + self.interval)
|
||||
if await wait_stop(self.interval, global_stop, self.user_stop):
|
||||
return
|
||||
await self.refresh()
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from euniv.study_window import month_key, window_open
|
||||
@@ -148,6 +150,11 @@ def assemble(account, live: dict | None = None, now: datetime | None = None) ->
|
||||
if recorded_month and recorded_month != month_key(now):
|
||||
stored_hours = ""
|
||||
payload["month_hours"] = cached_hours or stored_hours
|
||||
refresh_at = info.get("hours_refresh_at")
|
||||
left = 0
|
||||
if running and isinstance(refresh_at, (int, float)) and not isinstance(refresh_at, bool):
|
||||
left = max(0, int(math.ceil(float(refresh_at) - time.time())))
|
||||
payload["hours_refresh_in"] = left
|
||||
try:
|
||||
payload["monthly_target"] = int(getattr(account, "monthly_target", 0) or 0)
|
||||
except (TypeError, ValueError):
|
||||
|
||||
Reference in New Issue
Block a user