Skip to content

Commit

Permalink
feat(logging): add a status message when a csv is done importing with…
Browse files Browse the repository at this point in the history
… good/bad counts (#82)
  • Loading branch information
blackmad authored Nov 5, 2020
1 parent 702992f commit 94d7e0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/streams/documentStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function processRecord(record, next_uid, stats) {
getCategories(record)
.forEach(category => pelias_document.addCategory(category));

stats.goodRecordCount++;
return pelias_document;
} catch ( ex ){
logger.warn(`Record import failed on line ${next_uid} due to ${ex.message || ex}.`, record)
Expand Down
8 changes: 6 additions & 2 deletions lib/streams/recordStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function createRecordStream( filePath, dirPath ){
* A stream to convert rows of a CSV to Document objects.
*/
var stats = {
badRecordCount: 0
badRecordCount: 0,
goodRecordCount: 0
};

var csvParser = csvParse({
Expand All @@ -55,7 +56,10 @@ function createRecordStream( filePath, dirPath ){

return fs.createReadStream( filePath )
.pipe( csvParser )
.pipe( documentStream );
.pipe( documentStream )
.on('finish', () => {
logger.info(`Finished import from ${filePath}, goodRecordCount=${stats.goodRecordCount} badRecordCount=${stats.badRecordCount}`)
})
}

/*
Expand Down

0 comments on commit 94d7e0e

Please sign in to comment.