Throttle progress messages

This was part of the reason the process was dying out of memory since
we were sending too many messages (I guess it was all getting buffered up)

Part of #626
This commit is contained in:
Girish Ramakrishnan
2019-04-03 11:43:12 -07:00
parent 5a4c2a4974
commit 152cb48340

View File

@@ -37,10 +37,22 @@ process.on('disconnect', function () {
process.exit(0);
});
// send progress every n seconds
function throttledProgressCallback(msecs) {
let lastProgress = null;
return function (progress) {
let now = Date.now();
if (lastProgress && ((now - lastProgress) < msecs)) return;
process.send(progress);
lastProgress = now;
};
}
initialize(function (error) {
if (error) throw error;
backups.upload(backupId, format, dataLayoutString, (progress) => process.send(progress), function resultHandler(error) {
backups.upload(backupId, format, dataLayoutString, throttledProgressCallback(5000), function resultHandler(error) {
if (error) debug('upload completed with error', error);
debug('upload completed');