Refactor code structure for improved readability and maintainability
This commit is contained in:
parent
7b30f17065
commit
c71e4b4cd0
27 changed files with 1738 additions and 324 deletions
|
|
@ -5,7 +5,6 @@ export const config = {
|
|||
workerTimeoutMs: Number(process.env.FACEAI_WORKER_TIMEOUT_MS || 5 * 60 * 1000),
|
||||
runtimeRoot: process.env.FACEAI_RUNTIME_ROOT || '/data/runtime',
|
||||
pklRoot: process.env.FACEAI_PKL_ROOT || '/data/pkl',
|
||||
fallbackPklRoot: process.env.FACEAI_TEST_PKL_ROOT || '/data/pkl/test',
|
||||
matcherBinary: process.env.FACEAI_MATCHER_BINARY || '/opt/face-recognition/face_matcher',
|
||||
searchTtlSeconds: Number(process.env.FACEAI_SEARCH_TTL_SECONDS || 24 * 60 * 60),
|
||||
resultTtlSeconds: Number(process.env.FACEAI_RESULT_TTL_SECONDS || 24 * 60 * 60)
|
||||
|
|
|
|||
|
|
@ -1,34 +1,22 @@
|
|||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { resolveRacePklAvailability } from '../../backend/src/race-storage.js';
|
||||
|
||||
async function fileExists(filePath) {
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export async function resolvePklPath({ raceId, raceStorage, pklRoot }) {
|
||||
const availability = await resolveRacePklAvailability({
|
||||
pklRoot,
|
||||
race: {
|
||||
id: raceId,
|
||||
storage: raceStorage
|
||||
}
|
||||
});
|
||||
|
||||
export async function resolvePklPath({ raceId, pklRoot, fallbackPklRoot }) {
|
||||
const preferred = path.join(pklRoot, String(raceId), 'face_encodings.pkl');
|
||||
if (await fileExists(preferred)) {
|
||||
return preferred;
|
||||
if (!availability.available || !availability.pklPath) {
|
||||
throw new Error(availability.message || `No PKL file available for race ${raceId}`);
|
||||
}
|
||||
|
||||
const flatFile = path.join(pklRoot, `${raceId}.pkl`);
|
||||
if (await fileExists(flatFile)) {
|
||||
return flatFile;
|
||||
}
|
||||
|
||||
const fallbackEntries = await fs.readdir(fallbackPklRoot).catch(() => []);
|
||||
const fallbackFile = fallbackEntries.find((entry) => entry.toLowerCase().endsWith('.pkl'));
|
||||
if (fallbackFile) {
|
||||
return path.join(fallbackPklRoot, fallbackFile);
|
||||
}
|
||||
|
||||
throw new Error(`No PKL file available for race ${raceId}`);
|
||||
return availability.pklPath;
|
||||
}
|
||||
|
||||
export async function runFaceMatcher({ matcherBinary, selfiePath, pklPath, csvPath, logPath, timeoutMs }) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ async function processJob(job) {
|
|||
try {
|
||||
const pklPath = await resolvePklPath({
|
||||
raceId: search.raceId,
|
||||
pklRoot: config.pklRoot,
|
||||
fallbackPklRoot: config.fallbackPklRoot
|
||||
raceStorage: search.raceStorage,
|
||||
pklRoot: config.pklRoot
|
||||
});
|
||||
|
||||
const csvPath = path.join(searchDir, 'result.csv');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue