Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var https = require("https");
var moment = require("moment");
var uuid = require("uuid");

const accessor = {};

module.exports = function (id, opts) {

opts = Object.assign({
Expand All @@ -24,7 +26,7 @@ module.exports = function (id, opts) {
keepAlive: true
})
},
credentials: configure.credentials
credentials: opts.credentials
});

var configFile = path.resolve(os.tmpdir(), `leolog_${id.toString()}.json`);
Expand Down Expand Up @@ -125,14 +127,15 @@ module.exports = function (id, opts) {
config.sequenceNumber = data.nextSequenceToken;
fs.writeFile(configFile, JSON.stringify(config, null, 2), callback);
}
})
});
logs = [];
}

});
}

var logger = {
sendEvents,
end: function (callback) {
process.stdout.write = oldStdOut;
process.stderr.write = oldStdErr;
Expand All @@ -149,7 +152,7 @@ module.exports = function (id, opts) {
process.once("beforeExit", () => {
logger.end((err) => {
if (err) {
console.log("Error uploading logs to aws:", err)
console.log("Error uploading logs to aws:", err);
}
console.log("Finished uploading logs", config.logGroupName);
});
Expand All @@ -159,6 +162,8 @@ module.exports = function (id, opts) {
// By catching and logging the error it adds to the event loop and causes "beforeExit" to fire
console.error(err);
});

accessor.logger = logger;
return logger;
};
};

module.exports.accessor = accessor;
37 changes: 29 additions & 8 deletions lib/stream/leo-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,30 @@ module.exports = function(configure) {
size: 1,
map: (payload, meta, done) => done(null, payload)
};

if (typeof opts.size != "object" && (opts.count || opts.records || opts.units || opts.time || opts.bytes)) {
opts.size = {};
opts.size.count = opts.count || opts.records || opts.units;
opts.size.time = opts.time;
opts.size.bytes = opts.size || opts.bytes;
opts.size.highWaterMark = opts.highWaterMark || 2;

}

if (!opts.batch || typeof opts.batch === "number") {
batch.size = opts.batch || batch.size;
} else {
batch.size = opts.batch.size || batch.size;
batch.map = opts.batch.map || batch.map;
}
if (typeof batch.size != "object") {
batch.size = {
count: batch.size
}
}
batch.size.highWaterMark = batch.size.highWaterMark || 2;

var batchSize = typeof batch.size === "number" ? batch.size : batch.size.count;
var batchSize = typeof batch.size === "number" ? batch.size : (batch.size.count || batch.size.records);
return ls.pipe(
ls.fromLeo(id, inQueue, opts),
ls.through((obj, done) => {
Expand All @@ -278,7 +294,9 @@ module.exports = function(configure) {
});
}),
ls.batch(batch.size),
ls.through((batch, done) => {
ls.through({
highWaterMark: 1
}, (batch, done) => {
batch.units = batch.payload.length;
let last = batch.payload[batch.units - 1];
if (batchSize == 1) {
Expand All @@ -290,12 +308,14 @@ module.exports = function(configure) {
done(null, batch);
}
}),
ls.process(id, func, null),
ls.process(id, func, null, undefined, {
highWaterMark: 1
}),
ls.toCheckpoint({
debug: opts.debug
}), callback);
},
process: function(id, func, outQueue, onflush) {
process: function(id, func, outQueue, onflush, opts = {}) {
var firstEvent;
var lastEvent;
var units;
Expand Down Expand Up @@ -343,7 +363,9 @@ module.exports = function(configure) {
}
reset();

return ls.through(function(obj, done) {
return ls.through({
highWaterMark: opts.highWaterMark
}, function(obj, done) {
if (!firstEvent) {
firstEvent = obj;
}
Expand Down Expand Up @@ -803,7 +825,6 @@ module.exports = function(configure) {
stream.on("end", function() {
console.log("end", arguments);
stream.checkpoint(opts || {}, () => {});
process.exit();
});

return stream;
Expand Down Expand Up @@ -923,7 +944,7 @@ module.exports = function(configure) {

logger.info(opts);
opts = Object.assign({
buffer: 1000,
buffer: 16,
loops: 100,
start: null,
limit: Number.POSITIVE_INFINITY,
Expand Down Expand Up @@ -1345,7 +1366,7 @@ module.exports = function(configure) {
logger.error(err);
done(err);
} else {
logger.debug("gzipped event read finished");
logger.debug("gzipped event read finished", item.records, totalCount);
done();
}
});
Expand Down
11 changes: 7 additions & 4 deletions lib/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ let ls = module.exports = {
stream.emit("error", err);
}
if (done) {
done(err);
done(err);
}
}, data);
} else {
Expand All @@ -199,7 +199,8 @@ let ls = module.exports = {
//want to add the flush statistics and send it further
done(null, obj);
});
}
},
highWaterMark: opts.highWaterMark || undefined
}, opts.commands), function(o, done) {
each.call(stream, o, (err, obj) => {
if (obj) {
Expand Down Expand Up @@ -579,7 +580,8 @@ let ls = module.exports = {
opts = Object.assign({
count: undefined,
bytes: undefined,
time: undefined
time: undefined,
highWaterMark: 2
}, opts);

var buffer = [];
Expand Down Expand Up @@ -617,6 +619,7 @@ let ls = module.exports = {
size: opts.size || opts.bytes,
records: opts.records || opts.count,
buffer: opts.buffer,
highWaterMark: opts.highWaterMark,
debug: opts.debug
}, function(obj, callback) {
let size = 0;
Expand All @@ -636,7 +639,7 @@ let ls = module.exports = {
});
}, function emit(callback, data) {
push(stream, data);
callback();
callback();
}, function flush(callback) {
logger.debug("Batch On Flush");
callback();
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": "leo-sdk",
"version": "1.0.68",
"version": "1.0.71",
"description": "Load data onto the LEO Platform",
"homepage": "https://leoplatform.io",
"main": "index.js",
Expand Down