From 696a866b67cc1d5cad2d0263d2f42e0777c130fc Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 23 Sep 2015 13:38:57 +0100 Subject: [PATCH] pause the stream of ops, not the download the download is buffered in the lineStream so a lot comes out even after pausing the S3 download. --- services/track-changes/app/coffee/MongoAWS.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/track-changes/app/coffee/MongoAWS.coffee b/services/track-changes/app/coffee/MongoAWS.coffee index f2ad22bdf4..e9fb3b76d2 100644 --- a/services/track-changes/app/coffee/MongoAWS.coffee +++ b/services/track-changes/app/coffee/MongoAWS.coffee @@ -64,20 +64,21 @@ module.exports = MongoAWS = ops = [] sz = 0 - download + inputStream = download .on 'open', (obj) -> return 1 .on 'error', (err) -> callback(err) .pipe lineStream - .on 'data', (line) -> + + inputStream.on 'data', (line) -> if line.length > 2 ops.push(JSON.parse(line)) sz += line.length if ops.length >= MongoAWS.MAX_COUNT || sz >= MongoAWS.MAX_SIZE - download.pause() + inputStream.pause() MongoAWS.handleBulk ops.slice(0), sz, () -> - download.resume() + inputStream.resume() ops.splice(0,ops.length) sz = 0 .on 'end', () ->