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
+14 -3
View File
@@ -38,7 +38,7 @@ def _credential_lock(employee_id: str) -> threading.Lock:
with _credential_guard:
lock = _credential_locks.get(employee_id)
if lock is None:
lock = threading.Lock()
lock = threading.RLock()
_credential_locks[employee_id] = lock
return lock
@@ -104,6 +104,11 @@ def _drop_employee(employee_id: str) -> None:
def _persist(db: Session, employee_id: str, password: str | None, client: EunivClient, profile: dict) -> None:
with _credential_lock(employee_id):
_persist_locked(db, employee_id, password, client, profile)
def _persist_locked(db: Session, employee_id: str, password: str | None, client: EunivClient, profile: dict) -> None:
from sqlalchemy.exc import IntegrityError
client.authorize(profile)
@@ -421,6 +426,7 @@ def _live(db: Session, employee_id: str, client_factory, read):
credential = json.loads(decrypt_secret(account.credential_cipher))
attempts = _auto_attempts(db)
password = decrypt_secret(account.password_cipher) if account.password_cipher else ""
db.commit()
last_exc: BaseException | None = None
for _ in range(MAX_SWITCHES + 1):
client = _client(client_factory, employee_id, password, account)
@@ -515,14 +521,19 @@ def _refresh_one(employee_id: str, attempts: int, client_factory) -> None:
password = decrypt_secret(account.password_cipher)
previous = json.loads(decrypt_secret(account.credential_cipher))
db.commit()
for _ in range(MAX_SWITCHES + 1):
client = _client(client_factory, employee_id, password, account)
try:
client.restore(previous)
if client.credential_alive():
updated = client.export_credential()
if _dump(updated) != _dump(previous):
account.credential_cipher = encrypt_secret(_dump(updated))
with _credential_lock(employee_id):
db.refresh(account)
current_raw = account.credential_cipher
current = json.loads(decrypt_secret(current_raw)) if current_raw else {}
if current_raw and _dump(current) == _dump(previous) and _dump(updated) != _dump(previous):
account.credential_cipher = encrypt_secret(_dump(updated))
valid = True
checked_alive = True
elif is_qr_password(password):