faces: очередь проверки лиц и страница «Сканер лиц»

Вынести распознавание лиц с загрузки в фоновую очередь:
- таблица face_scan_jobs (pending/processing/done/error) + воркер
  createFaceScanWorker (FOR UPDATE SKIP LOCKED, backoff, retry, очистка хвоста)
- дедупликация активных задач частичным уникальным индексом, ON CONFLICT
  обновляет photo_path
- scanFacesForPhoto теперь бросает ошибку вместо возврата null
- ручные эндпоинты scan-unscanned/scan-faces/rescan только ставят задачи
  и отвечают { queued, skipped, total }

Уведомления и SSE:
- face.scan.done (по умолчанию выключено), face.recognized, face.scan.error
- notifyFaceScan определяет филиал по источнику, SSE face_scan_status
  обновляет открытый вьюер лиц

Новая админ-страница «Сканер лиц» (faces.html, faces.js):
- мониторинг очереди и воркера, библиотека лиц, ошибки, аудит
- действия: wake, retry, clear, rematch, scan-unscanned
- GET /api/faces/monitor, POST /api/faces/queue/{wake,clear}

Обновлены AGENTS.md, db/init.sql, db/migration.sql (сид notify_face_*),
public/js/{groups,journal,settings}.js, public/admin.js, public/settings.html
This commit is contained in:
dev
2026-10-11 00:37:50 +03:00
parent 22466629c8
commit 8137fd35d5
12 changed files with 1480 additions and 72 deletions
+50
View File
@@ -1098,6 +1098,56 @@ if (faceRematchBtn) faceRematchBtn.addEventListener('click', async () => {
}
});
const faceQueueHint = document.getElementById('faceQueueHint');
const faceQueueRetryBtn = document.getElementById('faceQueueRetryBtn');
const faceQueueRefreshBtn = document.getElementById('faceQueueRefreshBtn');
let faceQueueTimer = null;
function renderFaceQueue(d) {
if (!faceQueueHint || !d) return;
const t = d.totals || {};
const w = d.worker || {};
const parts = [
`в очереди ${t.pending || 0}`,
`в работе ${t.processing || 0}`,
`готово ${t.done || 0}`,
];
if (t.error) parts.push(`ошибок ${t.error}`);
let text = `Очередь проверки: ${parts.join(' · ')}`;
if (w.last_error) text += ` · последняя ошибка: ${w.last_error}`;
faceQueueHint.textContent = text;
if (faceQueueRetryBtn) faceQueueRetryBtn.disabled = !(t.error > 0);
}
async function loadFaceQueue() {
try {
const res = await fetch(`${API}/api/faces/queue`, { headers: hdr() });
if (!res.ok) return;
renderFaceQueue(await res.json());
} catch { /* сеть недоступна — статус обновится при следующем тике */ }
}
if (faceQueueRefreshBtn) faceQueueRefreshBtn.addEventListener('click', loadFaceQueue);
if (faceQueueRetryBtn) faceQueueRetryBtn.addEventListener('click', async () => {
faceQueueRetryBtn.disabled = true;
try {
const res = await fetch(`${API}/api/faces/queue/retry`, { method: 'POST', headers: hdr() });
const d = await res.json().catch(() => ({}));
if (!res.ok) { showError(d.error || 'Не удалось повторить ошибки'); return; }
showToast(`В очередь возвращено: ${d.requeued}`);
loadFaceQueue();
} catch {
showError('Не удалось повторить ошибки');
} finally {
faceQueueRetryBtn.disabled = false;
}
});
if (faceQueueHint) {
loadFaceQueue();
faceQueueTimer = setInterval(loadFaceQueue, 5000);
window.addEventListener('beforeunload', () => { if (faceQueueTimer) clearInterval(faceQueueTimer); });
}
const notifyTestBtn = document.getElementById('notifyTestBtn');
if (notifyTestBtn) notifyTestBtn.addEventListener('click', async () => {
notifyTestBtn.classList.add('spinning');