Prevent database from closing before biometrics have finished.

This commit is contained in:
DebaucheryLibrarian
2026-11-19 05:08:03 +01:00
parent 695b845f38
commit e749e22006
2 changed files with 31 additions and 5 deletions
+21 -4
View File
@@ -863,6 +863,8 @@ async function getActorNames(actorNames) {
return actorsWithoutProfiles.rows.map((actor) => actor.name);
}
const pendingBiometrics = new Set();
async function storeProfiles(profiles) {
const profilesWithAvatarIds = await associateAvatars(profiles);
const actorIds = Array.from(new Set(profiles.map((profile) => profile.actorId)));
@@ -872,10 +874,24 @@ async function storeProfiles(profiles) {
await upsertProfiles(profilesWithAvatarIds);
await interpolateProfiles(actorIds);
setBiometrics(Array.from(new Set(profiles.map((profile) => profile.actorId)))).catch((error) => {
// biometrics are courtesy, don't await
logger.error(`Biometrics failed: ${error.message}`);
});
// biometrics are courtesy, don't hold up the scrape, but they must finish before the database pool is destroyed
const biometricsJob = setBiometrics(actorIds)
.catch((error) => {
logger.error(`Biometrics failed: ${error.message}`);
})
.finally(() => {
pendingBiometrics.delete(biometricsJob);
});
pendingBiometrics.add(biometricsJob);
}
async function waitForBiometrics() {
if (pendingBiometrics.size > 0) {
logger.info('Waiting for biometrics to finish');
}
await Promise.all(Array.from(pendingBiometrics));
}
async function scrapeActors(argNames) {
@@ -1261,4 +1277,5 @@ module.exports = {
scrapeActors,
searchActors,
toBaseActors,
waitForBiometrics,
};