Compare commits
2
Commits
2ef51591c1
...
252bfbf60b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
252bfbf60b | ||
|
|
72d2d660b8 |
@@ -274,14 +274,14 @@ def mark_failed(employee_id: str, proxy_url: str | None = None, reason: str = ""
|
|||||||
key = (employee_id or "").strip()
|
key = (employee_id or "").strip()
|
||||||
parsed = _parse_proxy_url(proxy_url)
|
parsed = _parse_proxy_url(proxy_url)
|
||||||
with SessionLocal() as db, _assign_lock:
|
with SessionLocal() as db, _assign_lock:
|
||||||
node = None
|
node = _find_node(db, parsed[0], parsed[1], parsed[2]) if parsed is not None else None
|
||||||
node_id = _holds.pop(key, None)
|
held = _holds.get(key)
|
||||||
if node_id:
|
if node is None and held is not None:
|
||||||
node = db.get(ProxyNode, node_id)
|
node = db.get(ProxyNode, held)
|
||||||
if node is None and parsed is not None:
|
|
||||||
node = _find_node(db, parsed[0], parsed[1], parsed[2])
|
|
||||||
if node is None:
|
if node is None:
|
||||||
return
|
return
|
||||||
|
if held == node.id:
|
||||||
|
_holds.pop(key, None)
|
||||||
node.status = STATUS_DEAD
|
node.status = STATUS_DEAD
|
||||||
node.fail_reason = (reason or "失效")[:200]
|
node.fail_reason = (reason or "失效")[:200]
|
||||||
node.last_checked_at = _now()
|
node.last_checked_at = _now()
|
||||||
|
|||||||
@@ -433,6 +433,8 @@ def _refresh_one(employee_id: str, attempts: int, client_factory) -> None:
|
|||||||
account = db.get(Account, employee_id)
|
account = db.get(Account, employee_id)
|
||||||
if account is None or account.refresh_paused or not account.credential_cipher:
|
if account is None or account.refresh_paused or not account.credential_cipher:
|
||||||
return
|
return
|
||||||
|
if account.credential_valid is False:
|
||||||
|
return
|
||||||
client = None
|
client = None
|
||||||
valid = False
|
valid = False
|
||||||
checked_alive = False
|
checked_alive = False
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class StudyControlError(ValueError):
|
|||||||
"""任务控制参数不符合要求。"""
|
"""任务控制参数不符合要求。"""
|
||||||
|
|
||||||
|
|
||||||
def start_now(account) -> None:
|
def start_now(account, now: datetime | None = None) -> None:
|
||||||
account.study_paused = False
|
account.study_paused = False
|
||||||
account.study_stop_month = ""
|
account.study_stop_month = month_key(now)
|
||||||
account.study_ignore_window = True
|
account.study_ignore_window = True
|
||||||
|
|
||||||
|
|
||||||
@@ -63,19 +63,26 @@ def hours_met(account, now: datetime | None = None) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def expire_pause(account, now: datetime | None = None) -> bool:
|
def expire_pause(account, now: datetime | None = None) -> bool:
|
||||||
"""本月停止不影响下月定时。遗留的无月份暂停记到当月。"""
|
"""本月的停止和立即开始都不带到下月。遗留的无月份暂停记到当月。"""
|
||||||
if not bool(getattr(account, "study_paused", False)):
|
|
||||||
return False
|
|
||||||
key = month_key(now)
|
key = month_key(now)
|
||||||
recorded = str(getattr(account, "study_stop_month", "") or "")
|
recorded = str(getattr(account, "study_stop_month", "") or "")
|
||||||
|
changed = False
|
||||||
|
if ignores_window(account) and recorded and recorded != key:
|
||||||
|
account.study_ignore_window = False
|
||||||
|
changed = True
|
||||||
|
if not bool(getattr(account, "study_paused", False)):
|
||||||
|
if changed:
|
||||||
|
account.study_stop_month = ""
|
||||||
|
return changed
|
||||||
if not recorded:
|
if not recorded:
|
||||||
account.study_stop_month = key
|
account.study_stop_month = key
|
||||||
return True
|
return True
|
||||||
if recorded != key:
|
if recorded != key:
|
||||||
account.study_paused = False
|
account.study_paused = False
|
||||||
account.study_stop_month = ""
|
account.study_stop_month = ""
|
||||||
|
account.study_ignore_window = False
|
||||||
return True
|
return True
|
||||||
return False
|
return changed
|
||||||
|
|
||||||
|
|
||||||
def eligible(account, now: datetime | None = None) -> bool:
|
def eligible(account, now: datetime | None = None) -> bool:
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ from euniv.study_control import (
|
|||||||
assemble,
|
assemble,
|
||||||
eligible as study_eligible,
|
eligible as study_eligible,
|
||||||
hours_met,
|
hours_met,
|
||||||
|
expire_pause,
|
||||||
start_now,
|
start_now,
|
||||||
stop_now,
|
stop_now,
|
||||||
view_of as study_view,
|
view_of as study_view,
|
||||||
@@ -413,6 +414,16 @@ def test_immediate_start_skips_monthly_window() -> None:
|
|||||||
assert study_eligible(account, datetime(2026, 11, 15, 13, 0, tzinfo=CN_TZ)) is False
|
assert study_eligible(account, datetime(2026, 11, 15, 13, 0, tzinfo=CN_TZ)) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_manual_start_expires_when_the_month_changes() -> None:
|
||||||
|
account = _Start(15, 0, 0, 0)
|
||||||
|
account.study_schedule_enabled = False
|
||||||
|
start_now(account, datetime(2026, 11, 20, tzinfo=CN_TZ))
|
||||||
|
assert study_eligible(account, datetime(2026, 11, 21, tzinfo=CN_TZ)) is True
|
||||||
|
assert expire_pause(account, datetime(2026, 12, 1, tzinfo=CN_TZ)) is True
|
||||||
|
assert account.study_ignore_window is False
|
||||||
|
assert study_eligible(account, datetime(2026, 12, 1, tzinfo=CN_TZ)) is False
|
||||||
|
|
||||||
|
|
||||||
def test_hours_met_clears_started_without_pause() -> None:
|
def test_hours_met_clears_started_without_pause() -> None:
|
||||||
account = _Start(1, 0, 0, 0)
|
account = _Start(1, 0, 0, 0)
|
||||||
start_now(account)
|
start_now(account)
|
||||||
|
|||||||
Reference in New Issue
Block a user