Skip to content

Commit

Permalink
Show how many works were added/skipped/failed after scan
Browse files Browse the repository at this point in the history
  • Loading branch information
nortonandrews committed Aug 30, 2019
1 parent 34d0791 commit bf2062b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/server/filesystem/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const processFolder = (id, folder) => db.knex('t_work')
if (count) {
// Already in database.
// console.log(` * ${folder} already in database, skipping.`);
return 1;
return 'skipped';
}

// New folder.
Expand Down Expand Up @@ -59,11 +59,11 @@ const processFolder = (id, folder) => db.knex('t_work')
metadata.dir = folder;
return db.insertWorkMetadata(metadata)
.then(console.log(` -> [RJ${rjcode}] Finished adding to the database!`))
.then(() => 0);
.then(() => 'added');
})
.catch((err) => {
console.log(` ! [RJ${rjcode}] Failed to fetch metadata from HVDB: ${err.message}`);
return 0;
return 'failed';
});
});

Expand Down Expand Up @@ -121,8 +121,16 @@ const performScan = () => {

Promise.all(promises)
.then((results) => {
const skipCount = results.reduce((a, b) => a + b, 0);
console.log(` * Finished scan. Skipped ${skipCount} folders already in database.`);
const counts = {
added: 0,
failed: 0,
skipped: 0,
};

// eslint-disable-next-line no-return-assign
results.forEach(x => counts[x] += 1);

console.log(` * Finished scan. Added ${counts.added}, skipped ${counts.skipped} and failed to add ${counts.failed} works.`);
db.knex.destroy();
})
.catch((err) => {
Expand Down

0 comments on commit bf2062b

Please sign in to comment.