Skip to content

Commit

Permalink
Merge pull request #3 from voldern/log-right-count
Browse files Browse the repository at this point in the history
Log right records count
  • Loading branch information
Espen Volden committed Nov 16, 2015
2 parents 1660992 + 72701ab commit ef69b56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.2] - 2015-11-16
### Fixed
- Log right amount of records. The records count that was logged was
doubled in previous release.

## [0.1.1] - 2015-11-16
### Fixed
- Do not write if there are no records in the queue when the stream gets closed
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ function ElasticsearchBulkIndexWritable(client, options) {
* @param {Function} callback
*/
ElasticsearchBulkIndexWritable.prototype.bulkWrite = function bulkWrite(records, callback) {
if (this.logger) {
this.logger.debug('Writing %d records to Elasticsearch', records.length);
}

this.client.bulk({ body: records }, function bulkCallback(err, data) {
if (err) {
err.records = records;
Expand All @@ -95,10 +91,6 @@ ElasticsearchBulkIndexWritable.prototype.bulkWrite = function bulkWrite(records,
return callback(error);
}

if (this.logger) {
this.logger.info('Wrote %d records to Elasticsearch', records.length);
}

callback();
}.bind(this));
};
Expand All @@ -121,11 +113,19 @@ ElasticsearchBulkIndexWritable.prototype._flush = function _flush(callback) {
return callback(error);
}

if (this.logger) {
this.logger.debug('Writing %d records to Elasticsearch', this.queue.length);
}

this.bulkWrite(records, function(err) {
if (err) {
return callback(err);
}

if (this.logger) {
this.logger.info('Wrote %d records to Elasticsearch', this.queue.length);
}

this.writtenRecords += this.queue.length;
this.queue = [];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elasticsearch-bulk-index-stream",
"version": "0.1.1",
"version": "0.1.2",
"description": "A writable stream for bulk indexing records in Elasticsearch",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ef69b56

Please sign in to comment.