fix: 一次保存学习配置,改代理后重开任务

This commit is contained in:
2026-11-16 11:13:45 +08:00
parent 556121a265
commit 7381b49e4c
11 changed files with 214 additions and 99 deletions
+22
View File
@@ -157,6 +157,25 @@ def _run(trigger: str) -> None:
_running = False
def _cool_failed_sync(employee_id: str, *, invalid: bool = False) -> None:
from euniv.db import SessionLocal
if not employee_id:
return
with SessionLocal() as db:
sync = db.get(CourseSync, 1)
if sync is None:
sync = CourseSync(id=1, last_employee_id=employee_id, course_count=0)
db.add(sync)
sync.last_employee_id = employee_id
sync.next_allowed_at = datetime.now(timezone.utc) + timedelta(minutes=30)
if invalid:
account = db.get(Account, employee_id)
if account is not None:
account.credential_valid = False
db.commit()
def _fetch_and_store(trigger: str) -> bool:
from euniv.client import EunivClient
from euniv.crypto import decrypt_secret
@@ -184,6 +203,7 @@ def _fetch_and_store(trigger: str) -> bool:
try:
client.restore(credential)
if not client.credential_alive():
_cool_failed_sync(employee_id, invalid=True)
return False
courses = client.list_courses()
last_exc = None
@@ -194,10 +214,12 @@ def _fetch_and_store(trigger: str) -> bool:
mark_failed(employee_id, proxy, str(exc)[:200])
proxy = bind_url(account)
continue
_cool_failed_sync(employee_id)
return False
finally:
client.close()
if last_exc is not None or not courses:
_cool_failed_sync(employee_id)
return False
with SessionLocal() as db:
db.execute(delete(Course))