@naturalcycles/datastore-lib 3.29.0 → 3.30.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.
|
@@ -26,24 +26,28 @@ class DatastoreStreamReadable extends node_stream_1.Readable {
|
|
|
26
26
|
batchSize: 1000,
|
|
27
27
|
...opt,
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
this.originalLimit = q.limitVal;
|
|
30
|
+
this.table = q.kinds[0];
|
|
31
|
+
logger.log(`!! using experimentalCursorStream !! ${this.table}, batchSize: ${opt.batchSize}`);
|
|
32
|
+
const { maxWait } = this.opt;
|
|
33
|
+
if (maxWait) {
|
|
34
|
+
this.logger.warn(`!! ${this.table} maxWait ${maxWait}`);
|
|
30
35
|
this.maxWaitInterval = setInterval(() => {
|
|
31
|
-
|
|
36
|
+
const millisSinceLastRead = Date.now() - this.lastReadTimestamp;
|
|
37
|
+
if (millisSinceLastRead < maxWait * 1000) {
|
|
38
|
+
this.logger.warn(`!! ${this.table} millisSinceLastRead(${millisSinceLastRead}) < maxWait*1000`);
|
|
32
39
|
return;
|
|
33
40
|
}
|
|
34
41
|
const { running, rowsRetrieved } = this;
|
|
35
|
-
this.logger.warn(`maxWait of ${
|
|
42
|
+
this.logger.warn(`maxWait of ${maxWait} seconds reached, force-triggering _read`, {
|
|
36
43
|
running,
|
|
37
44
|
rowsRetrieved,
|
|
38
45
|
});
|
|
39
46
|
// force-trigger _read
|
|
40
47
|
// regardless of `running` status
|
|
41
48
|
this._read();
|
|
42
|
-
}, (
|
|
49
|
+
}, (maxWait * 1000) / 2);
|
|
43
50
|
}
|
|
44
|
-
this.originalLimit = q.limitVal;
|
|
45
|
-
this.table = q.kinds[0];
|
|
46
|
-
logger.log(`!! using experimentalCursorStream !! ${this.table}, batchSize: ${opt.batchSize}`);
|
|
47
51
|
}
|
|
48
52
|
async runNextQuery() {
|
|
49
53
|
if (this.done)
|
|
@@ -85,6 +89,7 @@ class DatastoreStreamReadable extends node_stream_1.Readable {
|
|
|
85
89
|
rowsRetrieved: this.rowsRetrieved,
|
|
86
90
|
}, err);
|
|
87
91
|
this.emit('error', err);
|
|
92
|
+
clearInterval(this.maxWaitInterval);
|
|
88
93
|
return;
|
|
89
94
|
}
|
|
90
95
|
this.rowsRetrieved += rows.length;
|
package/package.json
CHANGED
|
@@ -35,34 +35,39 @@ export class DatastoreStreamReadable<T = any> extends Readable implements Readab
|
|
|
35
35
|
...opt,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
this.originalLimit = q.limitVal
|
|
39
|
+
this.table = q.kinds[0]!
|
|
40
|
+
|
|
41
|
+
logger.log(`!! using experimentalCursorStream !! ${this.table}, batchSize: ${opt.batchSize}`)
|
|
42
|
+
|
|
43
|
+
const { maxWait } = this.opt
|
|
44
|
+
if (maxWait) {
|
|
45
|
+
this.logger.warn(`!! ${this.table} maxWait ${maxWait}`)
|
|
46
|
+
|
|
39
47
|
this.maxWaitInterval = setInterval(
|
|
40
48
|
() => {
|
|
41
|
-
|
|
49
|
+
const millisSinceLastRead = Date.now() - this.lastReadTimestamp
|
|
50
|
+
|
|
51
|
+
if (millisSinceLastRead < maxWait * 1000) {
|
|
52
|
+
this.logger.warn(
|
|
53
|
+
`!! ${this.table} millisSinceLastRead(${millisSinceLastRead}) < maxWait*1000`,
|
|
54
|
+
)
|
|
42
55
|
return
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
const { running, rowsRetrieved } = this
|
|
46
|
-
this.logger.warn(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
rowsRetrieved,
|
|
51
|
-
},
|
|
52
|
-
)
|
|
59
|
+
this.logger.warn(`maxWait of ${maxWait} seconds reached, force-triggering _read`, {
|
|
60
|
+
running,
|
|
61
|
+
rowsRetrieved,
|
|
62
|
+
})
|
|
53
63
|
|
|
54
64
|
// force-trigger _read
|
|
55
65
|
// regardless of `running` status
|
|
56
66
|
this._read()
|
|
57
67
|
},
|
|
58
|
-
(
|
|
68
|
+
(maxWait * 1000) / 2,
|
|
59
69
|
)
|
|
60
70
|
}
|
|
61
|
-
|
|
62
|
-
this.originalLimit = q.limitVal
|
|
63
|
-
this.table = q.kinds[0]!
|
|
64
|
-
|
|
65
|
-
logger.log(`!! using experimentalCursorStream !! ${this.table}, batchSize: ${opt.batchSize}`)
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
private async runNextQuery(): Promise<void> {
|
|
@@ -117,6 +122,7 @@ export class DatastoreStreamReadable<T = any> extends Readable implements Readab
|
|
|
117
122
|
err,
|
|
118
123
|
)
|
|
119
124
|
this.emit('error', err)
|
|
125
|
+
clearInterval(this.maxWaitInterval)
|
|
120
126
|
return
|
|
121
127
|
}
|
|
122
128
|
|