Prevent database from closing before biometrics have finished.
This commit is contained in:
+21
-4
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user