Commit 44a6bad2 authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch '1-prevent-callback-to-call-twice' into 'master'

Call the callback once, even if the insert fail

Closes #1

See merge request !1
parents 64e00417 117a843e
......@@ -46,18 +46,19 @@ export class ElasticsearchTransformer extends Transform {
}
public async _transform(chunk, encoding, callback) {
this.batch.push(this.prepareMeta(chunk.parsed));
this.batch.push(this.prepareData(chunk.parsed));
if (this.batch.length > this.batchSize) {
try {
await this.client.bulk({body: this.batch});
} catch (err) {
console.error(err);
setTimeout(() => this._transform(chunk, encoding, callback), this.timeout);
this.batch.push(this.prepareData(chunk.parsed));
if (this.batch.length > this.batchSize) {
try {
await this.client.bulk({body: this.batch});
return setImmediate(callback);
} catch (err) {
console.error(err);
setTimeout(() => this._transform(chunk, encoding, callback), this.timeout);
}
this.batch = [];
} else {
return setImmediate(callback);
}
this.batch = [];
}
setImmediate(callback);
}
private prepareMeta(row) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment