fix: 一次保存学习配置,改代理后重开任务
This commit is contained in:
+36
-7
@@ -113,20 +113,38 @@ def _require(db: Session, employee_id: str) -> Account:
|
||||
|
||||
|
||||
def check_employee(db: Session, employee_id: str) -> dict:
|
||||
from euniv.proxy import bind_url, is_proxy_failure, url_of, uses_pool
|
||||
from euniv.proxy_pool import MAX_SWITCHES, mark_failed
|
||||
|
||||
account = _require(db, employee_id)
|
||||
if not account.credential_cipher:
|
||||
return {"employee_id": employee_id, "result": "未保存"}
|
||||
before_password = account.password_cipher
|
||||
before_credential = account.credential_cipher
|
||||
password = decrypt_secret(account.password_cipher) if account.password_cipher else ""
|
||||
credential = json.loads(decrypt_secret(account.credential_cipher))
|
||||
pooled = uses_pool(account)
|
||||
db.commit()
|
||||
client = None
|
||||
result = "检查失败"
|
||||
valid: bool | None = None
|
||||
try:
|
||||
client = _open_client(employee_id, decrypt_secret(account.password_cipher), url_of(account))
|
||||
client.restore(json.loads(decrypt_secret(account.credential_cipher)))
|
||||
alive = bool(client.credential_alive())
|
||||
result = "有效" if alive else "已失效"
|
||||
valid = alive
|
||||
for _ in range(MAX_SWITCHES + 1):
|
||||
proxy = bind_url(account) if pooled else url_of(account)
|
||||
client = _open_client(employee_id, password, proxy)
|
||||
try:
|
||||
client.restore(credential)
|
||||
alive = bool(client.credential_alive())
|
||||
result = "有效" if alive else "已失效"
|
||||
valid = alive
|
||||
break
|
||||
except Exception as exc:
|
||||
if pooled and proxy and is_proxy_failure(exc):
|
||||
mark_failed(employee_id, proxy, str(exc)[:200])
|
||||
client.close()
|
||||
client = None
|
||||
continue
|
||||
raise
|
||||
except Exception:
|
||||
db.rollback()
|
||||
account = db.get(Account, employee_id)
|
||||
@@ -239,6 +257,10 @@ def set_proxy(
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
db.commit()
|
||||
from euniv.autostudy import restart_work
|
||||
|
||||
for account in accounts:
|
||||
restart_work(account.employee_id)
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
@@ -247,6 +269,10 @@ def clear_proxy(db: Session, employee_ids: list[str]) -> dict:
|
||||
for account in accounts:
|
||||
clear(account)
|
||||
db.commit()
|
||||
from euniv.autostudy import restart_work
|
||||
|
||||
for account in accounts:
|
||||
restart_work(account.employee_id)
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
@@ -348,10 +374,13 @@ def set_study_settings(
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
db.commit()
|
||||
from euniv.autostudy import sync_work
|
||||
from euniv.autostudy import restart_work, sync_work
|
||||
|
||||
for account in accounts:
|
||||
sync_work(account.employee_id)
|
||||
if scheme is not None:
|
||||
restart_work(account.employee_id)
|
||||
else:
|
||||
sync_work(account.employee_id)
|
||||
return {"ok": True, "count": len(accounts)}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user