@naturalcycles/nodejs-lib 12.47.4 → 12.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -75,6 +75,14 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
75
75
|
* chunk is undefined for "final" stats, otherwise is defined.
|
|
76
76
|
*/
|
|
77
77
|
extra?: (chunk: IN | undefined, index: number) => AnyObject;
|
|
78
|
+
/**
|
|
79
|
+
* If specified - will multiply the counter by this number.
|
|
80
|
+
* Useful e.g when using `transformBuffer({ batchSize: 500 })`, so
|
|
81
|
+
* it'll accurately represent the number of processed entries (not batches).
|
|
82
|
+
*
|
|
83
|
+
* Defaults to 1.
|
|
84
|
+
*/
|
|
85
|
+
batchSize?: number;
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
88
|
* Pass-through transform that optionally logs progress.
|
|
@@ -15,7 +15,7 @@ const inspectOpt = {
|
|
|
15
15
|
* Pass-through transform that optionally logs progress.
|
|
16
16
|
*/
|
|
17
17
|
function transformLogProgress(opt = {}) {
|
|
18
|
-
const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = false, rss: logRss = true, peakRSS: logPeakRSS = true, logRPS = true, logEvery = 1000, extra, } = opt;
|
|
18
|
+
const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = false, rss: logRss = true, peakRSS: logPeakRSS = true, logRPS = true, logEvery = 1000, batchSize = 1, extra, } = opt;
|
|
19
19
|
const logProgress = opt.logProgress !== false && logEvery !== 0; // true by default
|
|
20
20
|
const logEvery10 = logEvery * 10;
|
|
21
21
|
const started = Date.now();
|
|
@@ -53,8 +53,9 @@ function transformLogProgress(opt = {}) {
|
|
|
53
53
|
const rps10 = Math.round(sma.push(lastRPS));
|
|
54
54
|
if (mem.rss > peakRSS)
|
|
55
55
|
peakRSS = mem.rss;
|
|
56
|
+
const batchedProgress = progress * batchSize;
|
|
56
57
|
console.log((0, util_1.inspect)({
|
|
57
|
-
[final ? `${metric}_final` : metric]:
|
|
58
|
+
[final ? `${metric}_final` : metric]: batchedProgress,
|
|
58
59
|
...(extra ? extra(chunk, progress) : {}),
|
|
59
60
|
...(logHeapUsed ? { heapUsed: (0, js_lib_1._mb)(mem.heapUsed) } : {}),
|
|
60
61
|
...(logHeapTotal ? { heapTotal: (0, js_lib_1._mb)(mem.heapTotal) } : {}),
|
package/package.json
CHANGED
|
@@ -92,6 +92,15 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
92
92
|
* chunk is undefined for "final" stats, otherwise is defined.
|
|
93
93
|
*/
|
|
94
94
|
extra?: (chunk: IN | undefined, index: number) => AnyObject
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* If specified - will multiply the counter by this number.
|
|
98
|
+
* Useful e.g when using `transformBuffer({ batchSize: 500 })`, so
|
|
99
|
+
* it'll accurately represent the number of processed entries (not batches).
|
|
100
|
+
*
|
|
101
|
+
* Defaults to 1.
|
|
102
|
+
*/
|
|
103
|
+
batchSize?: number
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
const inspectOpt: InspectOptions = {
|
|
@@ -113,6 +122,7 @@ export function transformLogProgress<IN = any>(
|
|
|
113
122
|
peakRSS: logPeakRSS = true,
|
|
114
123
|
logRPS = true,
|
|
115
124
|
logEvery = 1000,
|
|
125
|
+
batchSize = 1,
|
|
116
126
|
extra,
|
|
117
127
|
} = opt
|
|
118
128
|
const logProgress = opt.logProgress !== false && logEvery !== 0 // true by default
|
|
@@ -161,10 +171,12 @@ export function transformLogProgress<IN = any>(
|
|
|
161
171
|
const rps10 = Math.round(sma.push(lastRPS))
|
|
162
172
|
if (mem.rss > peakRSS) peakRSS = mem.rss
|
|
163
173
|
|
|
174
|
+
const batchedProgress = progress * batchSize
|
|
175
|
+
|
|
164
176
|
console.log(
|
|
165
177
|
inspect(
|
|
166
178
|
{
|
|
167
|
-
[final ? `${metric}_final` : metric]:
|
|
179
|
+
[final ? `${metric}_final` : metric]: batchedProgress,
|
|
168
180
|
...(extra ? extra(chunk, progress) : {}),
|
|
169
181
|
...(logHeapUsed ? { heapUsed: _mb(mem.heapUsed) } : {}),
|
|
170
182
|
...(logHeapTotal ? { heapTotal: _mb(mem.heapTotal) } : {}),
|