@statsig/client-core 3.31.1-beta.2 → 3.31.2
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.
- package/package.json +1 -1
- package/src/ErrorBoundary.d.ts +0 -2
- package/src/ErrorBoundary.js +3 -23
- package/src/EventLogger.d.ts +23 -14
- package/src/EventLogger.js +187 -85
- package/src/EventRetryConstants.d.ts +1 -3
- package/src/EventRetryConstants.js +1 -3
- package/src/NetworkCore.d.ts +0 -1
- package/src/NetworkCore.js +3 -5
- package/src/SessionID.d.ts +3 -3
- package/src/SessionID.js +82 -60
- package/src/StatsigClientBase.js +1 -1
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
- package/src/BatchedEventsQueue.d.ts +0 -14
- package/src/BatchedEventsQueue.js +0 -51
- package/src/EventSender.d.ts +0 -23
- package/src/EventSender.js +0 -96
- package/src/FlushCoordinator.d.ts +0 -50
- package/src/FlushCoordinator.js +0 -332
- package/src/FlushInterval.d.ts +0 -13
- package/src/FlushInterval.js +0 -44
- package/src/FlushTypes.d.ts +0 -7
- package/src/FlushTypes.js +0 -12
- package/src/PendingEvents.d.ts +0 -10
- package/src/PendingEvents.js +0 -26
package/src/FlushCoordinator.js
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.FlushCoordinator = void 0;
|
|
13
|
-
const EventRetryConstants_1 = require("./EventRetryConstants");
|
|
14
|
-
const EventSender_1 = require("./EventSender");
|
|
15
|
-
const FlushInterval_1 = require("./FlushInterval");
|
|
16
|
-
const FlushTypes_1 = require("./FlushTypes");
|
|
17
|
-
const Hashing_1 = require("./Hashing");
|
|
18
|
-
const Log_1 = require("./Log");
|
|
19
|
-
const NetworkCore_1 = require("./NetworkCore");
|
|
20
|
-
const StorageProvider_1 = require("./StorageProvider");
|
|
21
|
-
class FlushCoordinator {
|
|
22
|
-
constructor(batchQueue, pendingEvents, onPrepareFlush,
|
|
23
|
-
// For Event Sender
|
|
24
|
-
sdkKey, network, emitter, logEventUrlConfig, options, loggingEnabled, errorBoundary) {
|
|
25
|
-
this._cooldownTimer = null;
|
|
26
|
-
this._maxIntervalTimer = null;
|
|
27
|
-
this._hasRunQuickFlush = false;
|
|
28
|
-
this._currentFlushPromise = null;
|
|
29
|
-
this._creationTime = Date.now();
|
|
30
|
-
this._storageKey = null;
|
|
31
|
-
this._flushInterval = new FlushInterval_1.FlushInterval();
|
|
32
|
-
this._batchQueue = batchQueue;
|
|
33
|
-
this._pendingEvents = pendingEvents;
|
|
34
|
-
this._onPrepareFlush = onPrepareFlush;
|
|
35
|
-
this._errorBoundary = errorBoundary;
|
|
36
|
-
this._sdkKey = sdkKey;
|
|
37
|
-
this._eventSender = new EventSender_1.EventSender(sdkKey, network, emitter, logEventUrlConfig, options, loggingEnabled);
|
|
38
|
-
}
|
|
39
|
-
setLoggingEnabled(loggingEnabled) {
|
|
40
|
-
this._eventSender.setLoggingEnabled(loggingEnabled);
|
|
41
|
-
}
|
|
42
|
-
setLogEventCompressionMode(mode) {
|
|
43
|
-
this._eventSender.setLogEventCompressionMode(mode);
|
|
44
|
-
}
|
|
45
|
-
startScheduledFlushCycle() {
|
|
46
|
-
this._scheduleNextFlush();
|
|
47
|
-
}
|
|
48
|
-
stopScheduledFlushCycle() {
|
|
49
|
-
this._clearAllTimers();
|
|
50
|
-
}
|
|
51
|
-
addEvent(event) {
|
|
52
|
-
this._pendingEvents.addToPendingEventsQueue(event);
|
|
53
|
-
if (this._pendingEvents.hasEventsForFullBatch()) {
|
|
54
|
-
this.processLimitFlush();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
processManualFlush() {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
if (this._currentFlushPromise) {
|
|
60
|
-
yield this._currentFlushPromise;
|
|
61
|
-
}
|
|
62
|
-
this._currentFlushPromise = this._executeFlush(FlushTypes_1.FlushType.Manual).finally(() => {
|
|
63
|
-
this._currentFlushPromise = null;
|
|
64
|
-
this._scheduleNextFlush();
|
|
65
|
-
});
|
|
66
|
-
return this._currentFlushPromise;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
processShutdown() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if (this._currentFlushPromise) {
|
|
72
|
-
yield this._currentFlushPromise;
|
|
73
|
-
}
|
|
74
|
-
this._currentFlushPromise = this._executeFlush(FlushTypes_1.FlushType.Shutdown)
|
|
75
|
-
.catch((error) => {
|
|
76
|
-
Log_1.Log.error(`Error during shutdown flush: ${error}`);
|
|
77
|
-
})
|
|
78
|
-
.finally(() => {
|
|
79
|
-
this._currentFlushPromise = null;
|
|
80
|
-
});
|
|
81
|
-
return this._currentFlushPromise;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
_executeFlush(flushType) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
this._clearAllTimers();
|
|
87
|
-
try {
|
|
88
|
-
this._prepareQueueForFlush(flushType);
|
|
89
|
-
const batches = this._batchQueue.takeAllBatches();
|
|
90
|
-
if (batches.length === 0) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
yield Promise.all(batches.map((batch) => this._processOneBatch(batch, flushType)));
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
this._scheduleNextFlush();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
checkQuickFlush() {
|
|
101
|
-
if (this._hasRunQuickFlush) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (Date.now() - this._creationTime >
|
|
105
|
-
EventRetryConstants_1.EventRetryConstants.QUICK_FLUSH_WINDOW_MS) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
this._hasRunQuickFlush = true;
|
|
109
|
-
setTimeout(() => {
|
|
110
|
-
this.processManualFlush().catch((error) => {
|
|
111
|
-
Log_1.Log.warn('Quick flush failed:', error);
|
|
112
|
-
});
|
|
113
|
-
}, EventRetryConstants_1.EventRetryConstants.QUICK_FLUSH_WINDOW_MS);
|
|
114
|
-
}
|
|
115
|
-
_attemptScheduledFlush() {
|
|
116
|
-
if (this._currentFlushPromise) {
|
|
117
|
-
this._scheduleNextFlush();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const shouldFlushBySize = this.containsAtLeastOneFullBatch();
|
|
121
|
-
const shouldFlushByTime = this._flushInterval.hasReachedMaxInterval();
|
|
122
|
-
if (!shouldFlushBySize && !shouldFlushByTime) {
|
|
123
|
-
this._scheduleNextFlush();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this._flushInterval.markFlushAttempt();
|
|
127
|
-
let flushType;
|
|
128
|
-
if (shouldFlushBySize) {
|
|
129
|
-
flushType = FlushTypes_1.FlushType.ScheduledFullBatch;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
flushType = FlushTypes_1.FlushType.ScheduledMaxTime;
|
|
133
|
-
}
|
|
134
|
-
this._currentFlushPromise = this._processNextBatch(flushType)
|
|
135
|
-
.then(() => {
|
|
136
|
-
//This discards boolean result. Main goal here is to track completion
|
|
137
|
-
})
|
|
138
|
-
.catch((error) => {
|
|
139
|
-
Log_1.Log.error('Error during scheduled flush:', error);
|
|
140
|
-
})
|
|
141
|
-
.finally(() => {
|
|
142
|
-
this._currentFlushPromise = null;
|
|
143
|
-
this._scheduleNextFlush();
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
processLimitFlush() {
|
|
147
|
-
if (!this._flushInterval.hasCompletelyRecoveredFromBackoff()) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (this._currentFlushPromise) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
this._currentFlushPromise = this._processLimitFlushInternal()
|
|
154
|
-
.catch((error) => {
|
|
155
|
-
Log_1.Log.error(`Error during limit flush`, error);
|
|
156
|
-
})
|
|
157
|
-
.finally(() => {
|
|
158
|
-
this._currentFlushPromise = null;
|
|
159
|
-
this._scheduleNextFlush();
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
_processLimitFlushInternal() {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const success = yield this._processNextBatch(FlushTypes_1.FlushType.Limit);
|
|
165
|
-
if (!success) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
while (this._flushInterval.hasCompletelyRecoveredFromBackoff() &&
|
|
169
|
-
this.containsAtLeastOneFullBatch()) {
|
|
170
|
-
const success = yield this._processNextBatch(FlushTypes_1.FlushType.Limit);
|
|
171
|
-
if (!success) {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
_scheduleNextFlush() {
|
|
178
|
-
this._clearAllTimers();
|
|
179
|
-
const cooldownDelay = Math.max(0, this._flushInterval.getTimeUntilNextFlush());
|
|
180
|
-
this._cooldownTimer = setTimeout(() => {
|
|
181
|
-
this._cooldownTimer = null;
|
|
182
|
-
this._attemptScheduledFlush();
|
|
183
|
-
}, cooldownDelay);
|
|
184
|
-
const maxIntervalDelay = Math.max(0, this._flushInterval.getTimeTillMaxInterval());
|
|
185
|
-
this._maxIntervalTimer = setTimeout(() => {
|
|
186
|
-
this._maxIntervalTimer = null;
|
|
187
|
-
this._attemptScheduledFlush();
|
|
188
|
-
}, maxIntervalDelay);
|
|
189
|
-
}
|
|
190
|
-
_clearAllTimers() {
|
|
191
|
-
if (this._cooldownTimer !== null) {
|
|
192
|
-
clearTimeout(this._cooldownTimer);
|
|
193
|
-
this._cooldownTimer = null;
|
|
194
|
-
}
|
|
195
|
-
if (this._maxIntervalTimer !== null) {
|
|
196
|
-
clearTimeout(this._maxIntervalTimer);
|
|
197
|
-
this._maxIntervalTimer = null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
_processNextBatch(flushType) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
this._prepareQueueForFlush(flushType);
|
|
203
|
-
const batch = this._batchQueue.takeNextBatch();
|
|
204
|
-
if (!batch) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
return this._processOneBatch(batch, flushType);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
_processOneBatch(batch, flushType) {
|
|
211
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
const result = yield this._eventSender.sendBatch(batch);
|
|
213
|
-
if (result.success) {
|
|
214
|
-
this._flushInterval.adjustForSuccess();
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
this._flushInterval.adjustForFailure();
|
|
218
|
-
this._handleFailure(batch, flushType, result.statusCode);
|
|
219
|
-
return false;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
_prepareQueueForFlush(flushType) {
|
|
223
|
-
this._onPrepareFlush();
|
|
224
|
-
const droppedCount = this.convertPendingEventsToBatches();
|
|
225
|
-
if (droppedCount > 0) {
|
|
226
|
-
Log_1.Log.warn(`Dropped ${droppedCount} events`);
|
|
227
|
-
this._errorBoundary.logDroppedEvents(droppedCount, `Batch queue limit reached`, {
|
|
228
|
-
loggingInterval: this._flushInterval.getCurrentIntervalMs(),
|
|
229
|
-
batchSize: this._batchQueue.batchSize(),
|
|
230
|
-
maxPendingBatches: EventRetryConstants_1.EventRetryConstants.MAX_PENDING_BATCHES,
|
|
231
|
-
flushType: flushType,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
containsAtLeastOneFullBatch() {
|
|
236
|
-
return (this._pendingEvents.hasEventsForFullBatch() ||
|
|
237
|
-
this._batchQueue.hasFullBatch());
|
|
238
|
-
}
|
|
239
|
-
convertPendingEventsToBatches() {
|
|
240
|
-
if (this._pendingEvents.isEmpty()) {
|
|
241
|
-
return 0;
|
|
242
|
-
}
|
|
243
|
-
const allEvents = this._pendingEvents.takeAll();
|
|
244
|
-
return this._batchQueue.createBatches(allEvents);
|
|
245
|
-
}
|
|
246
|
-
_handleFailure(batch, flushType, statusCode) {
|
|
247
|
-
if (flushType === FlushTypes_1.FlushType.Shutdown) {
|
|
248
|
-
Log_1.Log.warn(`${flushType} flush failed during shutdown. ` +
|
|
249
|
-
`${batch.events.length} event(s) will be saved to storage for retry in next session.`);
|
|
250
|
-
this._saveShutdownFailedEventsToStorage(batch.events);
|
|
251
|
-
this._errorBoundary.logEventRequestFailure(batch.events.length, `flush failed during shutdown - saved to storage`, flushType, statusCode);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (!NetworkCore_1.RETRYABLE_CODES.has(statusCode)) {
|
|
255
|
-
Log_1.Log.warn(`${flushType} flush failed after ${batch.attempts} attempt(s). ` +
|
|
256
|
-
`${batch.events.length} event(s) will be dropped. Non-retryable error: ${statusCode}`);
|
|
257
|
-
this._errorBoundary.logEventRequestFailure(batch.events.length, `non-retryable error`, flushType, statusCode);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
if (batch.attempts >= EventRetryConstants_1.EventRetryConstants.MAX_RETRY_ATTEMPTS) {
|
|
261
|
-
Log_1.Log.warn(`${flushType} flush failed after ${batch.attempts} attempt(s). ` +
|
|
262
|
-
`${batch.events.length} event(s) will be dropped.`);
|
|
263
|
-
this._errorBoundary.logEventRequestFailure(batch.events.length, `max retry attempts exceeded`, flushType, statusCode);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
batch.incrementAttempts();
|
|
267
|
-
const droppedCount = this._batchQueue.requeueBatch(batch);
|
|
268
|
-
if (droppedCount > 0) {
|
|
269
|
-
Log_1.Log.warn(`Failed to requeue batch : dropped ${droppedCount} events due to full queue`);
|
|
270
|
-
this._errorBoundary.logDroppedEvents(droppedCount, `Batch queue limit reached`, {
|
|
271
|
-
loggingInterval: this._flushInterval.getCurrentIntervalMs(),
|
|
272
|
-
batchSize: this._batchQueue.batchSize(),
|
|
273
|
-
maxPendingBatches: EventRetryConstants_1.EventRetryConstants.MAX_PENDING_BATCHES,
|
|
274
|
-
flushType: flushType,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
loadAndRetryShutdownFailedEvents() {
|
|
279
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
const storageKey = this._getStorageKey();
|
|
281
|
-
try {
|
|
282
|
-
const events = this._getShutdownFailedEventsFromStorage(storageKey);
|
|
283
|
-
if (events.length === 0) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
Log_1.Log.debug(`Loading ${events.length} failed shutdown event(s) from storage for retry`);
|
|
287
|
-
StorageProvider_1.Storage.removeItem(storageKey);
|
|
288
|
-
events.forEach((event) => {
|
|
289
|
-
this.addEvent(event);
|
|
290
|
-
});
|
|
291
|
-
yield this.processManualFlush();
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
Log_1.Log.warn('Failed to load and retry failed shutdown events:', error);
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
_getStorageKey() {
|
|
299
|
-
if (!this._storageKey) {
|
|
300
|
-
this._storageKey = `statsig.failed_shutdown_events.${(0, Hashing_1._DJB2)(this._sdkKey)}`;
|
|
301
|
-
}
|
|
302
|
-
return this._storageKey;
|
|
303
|
-
}
|
|
304
|
-
_saveShutdownFailedEventsToStorage(events) {
|
|
305
|
-
const storageKey = this._getStorageKey();
|
|
306
|
-
try {
|
|
307
|
-
const existingEvents = this._getShutdownFailedEventsFromStorage(storageKey);
|
|
308
|
-
let allEvents = [...existingEvents, ...events];
|
|
309
|
-
if (allEvents.length > EventRetryConstants_1.EventRetryConstants.MAX_LOCAL_STORAGE) {
|
|
310
|
-
allEvents = allEvents.slice(-EventRetryConstants_1.EventRetryConstants.MAX_LOCAL_STORAGE);
|
|
311
|
-
}
|
|
312
|
-
(0, StorageProvider_1._setObjectInStorage)(storageKey, allEvents);
|
|
313
|
-
Log_1.Log.debug(`Saved ${events.length} failed shutdown event(s) to storage (total stored: ${allEvents.length})`);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
Log_1.Log.warn('Unable to save failed shutdown events to storage:', error);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
_getShutdownFailedEventsFromStorage(storageKey) {
|
|
320
|
-
try {
|
|
321
|
-
const events = (0, StorageProvider_1._getObjectFromStorage)(storageKey);
|
|
322
|
-
if (Array.isArray(events)) {
|
|
323
|
-
return events;
|
|
324
|
-
}
|
|
325
|
-
return [];
|
|
326
|
-
}
|
|
327
|
-
catch (_a) {
|
|
328
|
-
return [];
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
exports.FlushCoordinator = FlushCoordinator;
|
package/src/FlushInterval.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class FlushInterval {
|
|
2
|
-
private _currentIntervalMs;
|
|
3
|
-
private _lastFlushAttemptTime;
|
|
4
|
-
getCurrentIntervalMs(): number;
|
|
5
|
-
markFlushAttempt(): void;
|
|
6
|
-
getTimeSinceLastAttempt(): number;
|
|
7
|
-
hasReachedMaxInterval(): boolean;
|
|
8
|
-
getTimeTillMaxInterval(): number;
|
|
9
|
-
hasCompletelyRecoveredFromBackoff(): boolean;
|
|
10
|
-
adjustForSuccess(): void;
|
|
11
|
-
adjustForFailure(): void;
|
|
12
|
-
getTimeUntilNextFlush(): number;
|
|
13
|
-
}
|
package/src/FlushInterval.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlushInterval = void 0;
|
|
4
|
-
const MIN_FLUSH_INTERVAL_MS = 1000;
|
|
5
|
-
const MAX_FLUSH_INTERVAL_MS = 60000;
|
|
6
|
-
class FlushInterval {
|
|
7
|
-
constructor() {
|
|
8
|
-
this._currentIntervalMs = MIN_FLUSH_INTERVAL_MS;
|
|
9
|
-
this._lastFlushAttemptTime = Date.now();
|
|
10
|
-
}
|
|
11
|
-
getCurrentIntervalMs() {
|
|
12
|
-
return this._currentIntervalMs;
|
|
13
|
-
}
|
|
14
|
-
markFlushAttempt() {
|
|
15
|
-
this._lastFlushAttemptTime = Date.now();
|
|
16
|
-
}
|
|
17
|
-
getTimeSinceLastAttempt() {
|
|
18
|
-
return Date.now() - this._lastFlushAttemptTime;
|
|
19
|
-
}
|
|
20
|
-
hasReachedMaxInterval() {
|
|
21
|
-
return this.getTimeSinceLastAttempt() >= MAX_FLUSH_INTERVAL_MS;
|
|
22
|
-
}
|
|
23
|
-
getTimeTillMaxInterval() {
|
|
24
|
-
return MAX_FLUSH_INTERVAL_MS - this.getTimeSinceLastAttempt();
|
|
25
|
-
}
|
|
26
|
-
hasCompletelyRecoveredFromBackoff() {
|
|
27
|
-
return this._currentIntervalMs <= MIN_FLUSH_INTERVAL_MS;
|
|
28
|
-
}
|
|
29
|
-
adjustForSuccess() {
|
|
30
|
-
const current = this._currentIntervalMs;
|
|
31
|
-
if (current === MIN_FLUSH_INTERVAL_MS) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this._currentIntervalMs = Math.max(MIN_FLUSH_INTERVAL_MS, Math.floor(current / 2));
|
|
35
|
-
}
|
|
36
|
-
adjustForFailure() {
|
|
37
|
-
const current = this._currentIntervalMs;
|
|
38
|
-
this._currentIntervalMs = Math.min(MAX_FLUSH_INTERVAL_MS, current * 2);
|
|
39
|
-
}
|
|
40
|
-
getTimeUntilNextFlush() {
|
|
41
|
-
return this.getCurrentIntervalMs() - this.getTimeSinceLastAttempt();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.FlushInterval = FlushInterval;
|
package/src/FlushTypes.d.ts
DELETED
package/src/FlushTypes.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlushType = void 0;
|
|
4
|
-
/* eslint-disable no-restricted-syntax */
|
|
5
|
-
var FlushType;
|
|
6
|
-
(function (FlushType) {
|
|
7
|
-
FlushType["ScheduledMaxTime"] = "scheduled:max_time";
|
|
8
|
-
FlushType["ScheduledFullBatch"] = "scheduled:full_batch";
|
|
9
|
-
FlushType["Limit"] = "limit";
|
|
10
|
-
FlushType["Manual"] = "manual";
|
|
11
|
-
FlushType["Shutdown"] = "shutdown";
|
|
12
|
-
})(FlushType || (exports.FlushType = FlushType = {}));
|
package/src/PendingEvents.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { StatsigEventInternal } from './StatsigEvent';
|
|
2
|
-
export declare class PendingEvents {
|
|
3
|
-
private _pendingEvents;
|
|
4
|
-
private _batchSize;
|
|
5
|
-
constructor(batchSize: number);
|
|
6
|
-
addToPendingEventsQueue(event: StatsigEventInternal): void;
|
|
7
|
-
hasEventsForFullBatch(): boolean;
|
|
8
|
-
takeAll(): StatsigEventInternal[];
|
|
9
|
-
isEmpty(): boolean;
|
|
10
|
-
}
|
package/src/PendingEvents.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PendingEvents = void 0;
|
|
4
|
-
const Log_1 = require("./Log");
|
|
5
|
-
class PendingEvents {
|
|
6
|
-
constructor(batchSize) {
|
|
7
|
-
this._pendingEvents = [];
|
|
8
|
-
this._batchSize = batchSize;
|
|
9
|
-
}
|
|
10
|
-
addToPendingEventsQueue(event) {
|
|
11
|
-
this._pendingEvents.push(event);
|
|
12
|
-
Log_1.Log.debug('Enqueued Event:', event);
|
|
13
|
-
}
|
|
14
|
-
hasEventsForFullBatch() {
|
|
15
|
-
return this._pendingEvents.length >= this._batchSize;
|
|
16
|
-
}
|
|
17
|
-
takeAll() {
|
|
18
|
-
const events = this._pendingEvents;
|
|
19
|
-
this._pendingEvents = [];
|
|
20
|
-
return events;
|
|
21
|
-
}
|
|
22
|
-
isEmpty() {
|
|
23
|
-
return this._pendingEvents.length === 0;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.PendingEvents = PendingEvents;
|