From d9527a8c9eec77b3b56a06ebb2b70564586f4973 Mon Sep 17 00:00:00 2001 From: Jared Noble Date: Mon, 26 Mar 2018 14:30:29 -0700 Subject: [PATCH] added slicer recursing event for id_slicer resolves #611 --- lib/readers/elasticsearch_date_range/slicer.js | 2 +- lib/readers/id_reader.js | 2 +- lib/readers/id_slicer.js | 5 ++++- spec/readers/id_slicer-spec.js | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/readers/elasticsearch_date_range/slicer.js b/lib/readers/elasticsearch_date_range/slicer.js index 387cbdd4313..351f02df290 100644 --- a/lib/readers/elasticsearch_date_range/slicer.js +++ b/lib/readers/elasticsearch_date_range/slicer.js @@ -280,7 +280,7 @@ function newSlicer(context, opConfig, executionContext, retryData, logger, clien function makeKeyList(opConfig, data) { const idConfig = Object.assign({}, opConfig, { starting_key_depth: 0 }); - const idSlicer = require('../id_slicer')(client, executionContext, idConfig, logger, null, data); + const idSlicer = require('../id_slicer')(context, client, executionContext, idConfig, logger, null, data); return getIdData(idSlicer); } diff --git a/lib/readers/id_reader.js b/lib/readers/id_reader.js index 5c0372dd701..1a5f00442b2 100644 --- a/lib/readers/id_reader.js +++ b/lib/readers/id_reader.js @@ -9,7 +9,7 @@ function newSlicer(context, executionContext, retryData, logger) { const opConfig = getOpConfig(executionContext.config, 'id_reader'); const client = getClient(context, opConfig, 'elasticsearch'); - return require('./id_slicer')(client, executionContext, opConfig, logger, retryData); + return require('./id_slicer')(context, client, executionContext, opConfig, logger, retryData); } diff --git a/lib/readers/id_slicer.js b/lib/readers/id_slicer.js index 29dd0470b1c..a7d20f0aea0 100644 --- a/lib/readers/id_slicer.js +++ b/lib/readers/id_slicer.js @@ -13,7 +13,7 @@ const hexadecimal = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', const HEXADECIMAL = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; -module.exports = function (client, executionContext, opConfig, logger, retryData, range) { +module.exports = function (context, client, executionContext, opConfig, logger, retryData, range) { const keyRange = opConfig.key_range; const baseKeyArray = getKeyArray(opConfig); const keyArray = opConfig.key_range ? opConfig.key_range : baseKeyArray.slice(); @@ -21,6 +21,8 @@ module.exports = function (client, executionContext, opConfig, logger, retryData const elasticsearch = require('elasticsearch_api')(client, logger, opConfig); const executionConfig = executionContext.config; const retryError = retryModule(logger, executionConfig.max_retries); + const events = context.apis.foundation.getSystemEvents(); + function getCountForKey(query) { return elasticsearch.count(query); @@ -70,6 +72,7 @@ module.exports = function (client, executionContext, opConfig, logger, retryData return getCountForKey(query) .then((count) => { if (count >= opConfig.size) { + events.emit('slicer:slice:recursion'); return determineKeySlice(generator, false, rangeObj); } diff --git a/spec/readers/id_slicer-spec.js b/spec/readers/id_slicer-spec.js index 9a26ee109c1..32506d7275d 100644 --- a/spec/readers/id_slicer-spec.js +++ b/spec/readers/id_slicer-spec.js @@ -53,6 +53,11 @@ describe('id_reader', () => { error() {}, info() {}, warn() {} + }, + apis: { + foundation: { + getSystemEvents: () => eventEmitter + } } };