@rudderstack/workflow-engine
Version:
A generic workflow execution engine
48 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleBatchExecutor = void 0;
const batch_1 = require("../../../common/utils/batch");
class SimpleBatchExecutor {
constructor(config, filterMapExector) {
this.config = config;
this.filterMapExector = filterMapExector;
}
async execute(input, bindings) {
const { filteredInput, filteredIndices } = await this.handleFilteringAndMapping(input, bindings);
if (this.config.disabled) {
return this.handleBatchingDisabled(filteredInput, filteredIndices);
}
return this.handleBatching(filteredInput, filteredIndices);
}
handleBatching(filteredInput, filteredIndices) {
const { items: itemArrays, indices } = batch_1.BatchUtils.chunkArrayBySizeAndLength(filteredInput, {
maxSizeInBytes: this.config.options?.size,
maxItems: this.config.options?.length,
});
return itemArrays.map((items, index) => ({
items,
indices: indices[index].map((i) => filteredIndices[i]),
key: this.config.key,
}));
}
handleBatchingDisabled(filteredInput, filteredIndices) {
return filteredInput.map((item, index) => ({
items: [item],
indices: [filteredIndices[index]],
key: this.config.key,
}));
}
async handleFilteringAndMapping(input, bindings) {
let filteredInput = input;
let filteredIndices = Array.from(input.keys());
if (this.filterMapExector) {
// Filter map executor internally invokes the loop step executor
const filterResult = (await this.filterMapExector.execute(input, bindings));
filteredIndices = filteredIndices.filter((_, index) => !filterResult.output[index].skipped);
filteredInput = filteredIndices.map((index) => filterResult.output[index].output);
}
return { filteredInput, filteredIndices };
}
}
exports.SimpleBatchExecutor = SimpleBatchExecutor;
//# sourceMappingURL=simple_batch_executor.js.map