@splitsoftware/splitio-commons 0.1.1-canary.9 → 0.1.1-rc.18
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/cjs/evaluator/matchers/matcherTypes.js +4 -4
- package/cjs/evaluator/matchersTransform/index.js +11 -11
- package/cjs/evaluator/value/sanitize.js +6 -6
- package/cjs/listeners/browser.js +1 -2
- package/cjs/listeners/node.js +0 -3
- package/cjs/logger/constants.js +3 -1
- package/cjs/logger/messages/error.js +3 -2
- package/cjs/logger/messages/info.js +2 -2
- package/cjs/logger/messages/warn.js +2 -1
- package/cjs/readiness/readinessManager.js +10 -7
- package/cjs/sdkFactory/index.js +1 -4
- package/cjs/services/splitApi.js +1 -1
- package/cjs/services/splitHttpClient.js +5 -4
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/inLocalStorage/index.js +5 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/cjs/storages/inRedis/index.js +5 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +6 -7
- package/cjs/storages/pluggable/index.js +5 -2
- package/cjs/storages/pluggable/wrapperAdapter.js +0 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +92 -89
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +45 -42
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -4
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/cjs/sync/streaming/SSEClient/index.js +0 -11
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/cjs/sync/streaming/SSEHandler/index.js +8 -9
- package/cjs/sync/streaming/SSEHandler/types.js +14 -0
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/cjs/sync/streaming/constants.js +3 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +75 -0
- package/cjs/sync/streaming/pushManager.js +141 -40
- package/cjs/sync/submitters/metricsSyncTask.js +1 -1
- package/cjs/sync/submitters/submitterSyncTask.js +2 -2
- package/cjs/sync/syncManagerFromFile.js +15 -0
- package/cjs/sync/syncManagerFromObject.js +14 -0
- package/cjs/sync/syncManagerOffline.js +3 -3
- package/cjs/sync/syncManagerOnline.js +5 -3
- package/cjs/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/cjs/trackers/impressionObserver/buildKey.js +3 -9
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/cjs/utils/constants/index.js +4 -1
- package/cjs/utils/decompress/index.js +427 -0
- package/cjs/utils/murmur3/{commons.js → common.js} +2 -6
- package/cjs/utils/murmur3/murmur3.js +11 -12
- package/cjs/utils/murmur3/murmur3_128.js +7 -142
- package/cjs/utils/murmur3/murmur3_128_x86.js +154 -0
- package/cjs/utils/murmur3/murmur3_64.js +36 -0
- package/cjs/utils/murmur3/utfx.js +100 -106
- package/cjs/utils/promise/wrapper.js +14 -11
- package/cjs/utils/settingsValidation/index.js +5 -2
- package/cjs/utils/settingsValidation/localhost/index.js +20 -0
- package/cjs/utils/settingsValidation/splitFilters.js +0 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +18 -8
- package/cjs/utils/settingsValidation/url.js +1 -1
- package/esm/evaluator/matchers/matcherTypes.js +2 -2
- package/esm/evaluator/matchersTransform/index.js +12 -12
- package/esm/evaluator/value/sanitize.js +7 -7
- package/esm/listeners/browser.js +1 -2
- package/esm/listeners/node.js +0 -3
- package/esm/logger/constants.js +2 -0
- package/esm/logger/messages/error.js +3 -2
- package/esm/logger/messages/info.js +2 -2
- package/esm/logger/messages/warn.js +2 -1
- package/esm/readiness/readinessManager.js +10 -7
- package/esm/sdkFactory/index.js +1 -4
- package/esm/services/splitApi.js +1 -1
- package/esm/services/splitHttpClient.js +5 -4
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/inLocalStorage/index.js +5 -2
- package/esm/storages/inMemory/InMemoryStorage.js +2 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/esm/storages/inRedis/index.js +5 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +6 -7
- package/esm/storages/pluggable/index.js +5 -2
- package/esm/storages/pluggable/wrapperAdapter.js +0 -1
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +90 -88
- package/esm/sync/offline/splitsParser/splitsParserFromSettings.js +43 -41
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +15 -5
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/esm/sync/streaming/SSEClient/index.js +0 -11
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/esm/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/esm/sync/streaming/SSEHandler/index.js +9 -10
- package/esm/sync/streaming/SSEHandler/types.js +13 -1
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/esm/sync/streaming/constants.js +2 -0
- package/esm/sync/streaming/mySegmentsV2utils.js +69 -0
- package/esm/sync/streaming/pushManager.js +143 -42
- package/esm/sync/submitters/metricsSyncTask.js +1 -1
- package/esm/sync/submitters/submitterSyncTask.js +2 -2
- package/esm/sync/syncManagerFromFile.js +11 -0
- package/esm/sync/syncManagerFromObject.js +10 -0
- package/esm/sync/syncManagerOffline.js +3 -3
- package/esm/sync/syncManagerOnline.js +5 -3
- package/esm/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/esm/trackers/impressionObserver/buildKey.js +2 -9
- package/esm/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/esm/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/esm/utils/constants/index.js +3 -0
- package/esm/utils/decompress/index.js +424 -0
- package/esm/utils/murmur3/{commons.js → common.js} +1 -4
- package/esm/utils/murmur3/murmur3.js +1 -2
- package/esm/utils/murmur3/murmur3_128.js +7 -142
- package/esm/utils/murmur3/murmur3_128_x86.js +150 -0
- package/esm/utils/murmur3/murmur3_64.js +32 -0
- package/esm/utils/murmur3/utfx.js +96 -106
- package/esm/utils/promise/wrapper.js +14 -11
- package/esm/utils/settingsValidation/index.js +5 -2
- package/esm/utils/settingsValidation/localhost/index.js +16 -0
- package/esm/utils/settingsValidation/splitFilters.js +0 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +16 -7
- package/esm/utils/settingsValidation/url.js +1 -1
- package/package.json +5 -5
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +12 -12
- package/src/evaluator/value/sanitize.ts +7 -7
- package/src/listeners/browser.ts +1 -1
- package/src/listeners/node.ts +1 -2
- package/src/logger/constants.ts +2 -0
- package/src/logger/messages/error.ts +3 -2
- package/src/logger/messages/info.ts +2 -2
- package/src/logger/messages/warn.ts +3 -1
- package/src/readiness/readinessManager.ts +9 -7
- package/src/sdkFactory/index.ts +1 -3
- package/src/sdkFactory/types.ts +3 -3
- package/src/services/splitApi.ts +2 -3
- package/src/services/splitHttpClient.ts +6 -5
- package/src/services/types.ts +5 -5
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/inLocalStorage/index.ts +8 -4
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -1
- package/src/storages/inRedis/index.ts +8 -4
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -1
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -7
- package/src/storages/pluggable/index.ts +8 -4
- package/src/storages/pluggable/wrapperAdapter.ts +0 -1
- package/src/storages/types.ts +18 -15
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +110 -105
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +45 -41
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +15 -5
- package/src/sync/polling/types.ts +2 -1
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
- package/src/sync/streaming/AuthClient/types.ts +3 -0
- package/src/sync/streaming/SSEClient/index.ts +1 -15
- package/src/sync/streaming/SSEClient/types.ts +0 -1
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +8 -0
- package/src/sync/streaming/SSEHandler/NotificationParser.ts +4 -2
- package/src/sync/streaming/SSEHandler/index.ts +11 -20
- package/src/sync/streaming/SSEHandler/types.ts +37 -3
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +7 -6
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +4 -3
- package/src/sync/streaming/UpdateWorkers/types.ts +1 -1
- package/src/sync/streaming/constants.ts +2 -0
- package/src/sync/streaming/mySegmentsV2utils.ts +77 -0
- package/src/sync/streaming/pushManager.ts +139 -42
- package/src/sync/streaming/types.ts +14 -22
- package/src/sync/submitters/metricsSyncTask.ts +1 -1
- package/src/sync/submitters/submitterSyncTask.ts +2 -1
- package/src/sync/syncManagerFromFile.ts +13 -0
- package/src/sync/syncManagerFromObject.ts +12 -0
- package/src/sync/syncManagerOffline.ts +3 -3
- package/src/sync/syncManagerOnline.ts +6 -3
- package/src/trackers/impressionObserver/ImpressionObserver.ts +4 -6
- package/src/trackers/impressionObserver/buildKey.ts +2 -16
- package/src/trackers/impressionObserver/impressionObserverCS.ts +2 -2
- package/src/trackers/impressionObserver/impressionObserverSS.ts +3 -3
- package/src/types.ts +16 -2
- package/src/utils/constants/index.ts +6 -1
- package/src/utils/decompress/index.ts +429 -0
- package/src/utils/murmur3/{commons.ts → common.ts} +1 -5
- package/src/utils/murmur3/murmur3.ts +5 -5
- package/src/utils/murmur3/murmur3_128.ts +7 -180
- package/src/utils/murmur3/murmur3_128_x86.ts +188 -0
- package/src/utils/murmur3/murmur3_64.ts +36 -0
- package/src/utils/murmur3/utfx.ts +92 -110
- package/src/utils/promise/wrapper.ts +12 -9
- package/src/utils/settingsValidation/index.ts +8 -4
- package/src/utils/settingsValidation/localhost/index.ts +19 -0
- package/src/utils/settingsValidation/splitFilters.ts +0 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
- package/src/utils/settingsValidation/types.ts +2 -11
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/evaluator/matchers/matcherTypes.d.ts +2 -2
- package/types/listeners/browser.d.ts +1 -0
- package/types/listeners/node.d.ts +0 -1
- package/types/logger/constants.d.ts +2 -0
- package/types/sdkFactory/types.d.ts +3 -3
- package/types/services/types.d.ts +1 -0
- package/types/storages/inLocalStorage/index.d.ts +2 -2
- package/types/storages/inMemory/InMemoryStorage.d.ts +3 -0
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +3 -0
- package/types/storages/inRedis/index.d.ts +2 -2
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/types.d.ts +15 -15
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -7
- package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +1 -5
- package/types/sync/polling/types.d.ts +2 -1
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/AuthClient/types.d.ts +2 -0
- package/types/sync/streaming/SSEClient/index.d.ts +1 -9
- package/types/sync/streaming/SSEClient/types.d.ts +0 -1
- package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +3 -2
- package/types/sync/streaming/SSEHandler/types.d.ts +30 -2
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -3
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -1
- package/types/sync/streaming/constants.d.ts +3 -1
- package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/types.d.ts +9 -5
- package/types/sync/submitters/submitterSyncTask.d.ts +1 -1
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +1 -1
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +2 -2
- package/types/trackers/impressionObserver/buildKey.d.ts +1 -1
- package/types/trackers/impressionObserver/impressionObserverCS.d.ts +2 -2
- package/types/trackers/impressionObserver/impressionObserverSS.d.ts +2 -2
- package/types/types.d.ts +16 -2
- package/types/utils/constants/index.d.ts +5 -1
- package/types/utils/decompress/index.d.ts +16 -0
- package/types/utils/murmur3/common.d.ts +12 -0
- package/types/utils/murmur3/murmur3.d.ts +2 -2
- package/types/utils/murmur3/murmur3_128.d.ts +5 -0
- package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
- package/types/utils/murmur3/murmur3_64.d.ts +10 -0
- package/types/utils/murmur3/utfx.d.ts +24 -6
- package/types/utils/settingsValidation/index.d.ts +3 -2
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/storage/storageCS.d.ts +7 -1
- package/types/utils/settingsValidation/types.d.ts +2 -10
- package/cjs/sync/streaming/pushManagerCS.js +0 -179
- package/cjs/sync/streaming/pushManagerSS.js +0 -128
- package/esm/sync/streaming/pushManagerCS.js +0 -175
- package/esm/sync/streaming/pushManagerSS.js +0 -124
- package/src/sync/streaming/pushManagerCS.ts +0 -238
- package/src/sync/streaming/pushManagerSS.ts +0 -177
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { IPushEventEmitter, IPushManager } from './types';
|
|
2
|
-
import { ISSEClient } from './SSEClient/types';
|
|
3
|
-
import { IStorageSync } from '../../storages/types';
|
|
4
|
-
import { IPollingManager } from '../polling/types';
|
|
5
|
-
import { IReadinessManager } from '../../readiness/types';
|
|
6
|
-
import objectAssign from 'object-assign';
|
|
7
|
-
import { PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP } from './constants';
|
|
8
|
-
import Backoff from '../../utils/Backoff';
|
|
9
|
-
import SSEHandlerFactory from './SSEHandler';
|
|
10
|
-
import SegmentsUpdateWorker from './UpdateWorkers/SegmentsUpdateWorker';
|
|
11
|
-
import SplitsUpdateWorker from './UpdateWorkers/SplitsUpdateWorker';
|
|
12
|
-
import { IFetchAuth } from '../../services/types';
|
|
13
|
-
import { authenticateFactory } from './AuthClient';
|
|
14
|
-
import SSEClient from './SSEClient';
|
|
15
|
-
import { ISettings } from '../../types';
|
|
16
|
-
import { IPlatform } from '../../sdkFactory/types';
|
|
17
|
-
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT } from '../../logger/constants';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* PushManager factory for server-side
|
|
21
|
-
*/
|
|
22
|
-
export default function pushManagerSSFactory(
|
|
23
|
-
pollingManager: IPollingManager,
|
|
24
|
-
storage: IStorageSync,
|
|
25
|
-
readiness: IReadinessManager,
|
|
26
|
-
fetchAuth: IFetchAuth,
|
|
27
|
-
platform: IPlatform,
|
|
28
|
-
settings: ISettings
|
|
29
|
-
): IPushManager | undefined {
|
|
30
|
-
|
|
31
|
-
const log = settings.log;
|
|
32
|
-
|
|
33
|
-
let sseClient: ISSEClient;
|
|
34
|
-
try {
|
|
35
|
-
sseClient = new SSEClient(settings, true, platform.getEventSource);
|
|
36
|
-
} catch (e) {
|
|
37
|
-
log.warn(STREAMING_FALLBACK, [e]);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const authenticate = authenticateFactory(fetchAuth);
|
|
41
|
-
|
|
42
|
-
// init feedback loop (pushEmitter)
|
|
43
|
-
const pushEmitter = new platform.EventEmitter() as IPushEventEmitter;
|
|
44
|
-
const sseHandler = SSEHandlerFactory(log, pushEmitter);
|
|
45
|
-
sseClient.setEventHandler(sseHandler);
|
|
46
|
-
|
|
47
|
-
// init workers
|
|
48
|
-
const splitsUpdateWorker = new SplitsUpdateWorker(storage.splits, pollingManager.splitsSyncTask, readiness.splits, pollingManager.segmentsSyncTask);
|
|
49
|
-
const segmentsUpdateWorker = new SegmentsUpdateWorker(storage.segments, pollingManager.segmentsSyncTask);
|
|
50
|
-
|
|
51
|
-
// flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error.
|
|
52
|
-
// It is used to halt the `connectPush` process if it was in progress.
|
|
53
|
-
let disconnected: boolean | undefined;
|
|
54
|
-
|
|
55
|
-
/** PushManager functions related to initialization */
|
|
56
|
-
|
|
57
|
-
const connectPushRetryBackoff = new Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
58
|
-
|
|
59
|
-
let timeoutId: ReturnType<typeof setTimeout>;
|
|
60
|
-
|
|
61
|
-
function scheduleTokenRefresh(issuedAt: number, expirationTime: number) {
|
|
62
|
-
// clear scheduled token refresh if exists (needed when resuming PUSH)
|
|
63
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
64
|
-
|
|
65
|
-
// Set token refresh 10 minutes before expirationTime
|
|
66
|
-
const delayInSeconds = expirationTime - issuedAt - SECONDS_BEFORE_EXPIRATION;
|
|
67
|
-
|
|
68
|
-
log.info(STREAMING_REFRESH_TOKEN, [delayInSeconds]);
|
|
69
|
-
|
|
70
|
-
timeoutId = setTimeout(connectPush, delayInSeconds * 1000);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function connectPush() {
|
|
74
|
-
disconnected = false;
|
|
75
|
-
log.info(STREAMING_CONNECTING);
|
|
76
|
-
|
|
77
|
-
authenticate().then(
|
|
78
|
-
function (authData) {
|
|
79
|
-
if (disconnected) return;
|
|
80
|
-
|
|
81
|
-
// 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
82
|
-
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
83
|
-
if (!authData.pushEnabled) {
|
|
84
|
-
log.info(STREAMING_DISABLED);
|
|
85
|
-
pushEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Connect to SSE and schedule refresh token
|
|
90
|
-
const decodedToken = authData.decodedToken;
|
|
91
|
-
sseClient.open(authData);
|
|
92
|
-
scheduleTokenRefresh(decodedToken.iat, decodedToken.exp);
|
|
93
|
-
}
|
|
94
|
-
).catch(
|
|
95
|
-
function (error) {
|
|
96
|
-
if (disconnected) return;
|
|
97
|
-
|
|
98
|
-
log.error(ERROR_STREAMING_AUTH, [error.message]);
|
|
99
|
-
|
|
100
|
-
// Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
|
|
101
|
-
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
102
|
-
pushEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Handle other HTTP and network errors as recoverable errors
|
|
107
|
-
pushEmitter.emit(PUSH_RETRYABLE_ERROR);
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// close SSE connection and cancel scheduled tasks
|
|
113
|
-
function disconnectPush() {
|
|
114
|
-
sseClient.close();
|
|
115
|
-
disconnected = true;
|
|
116
|
-
log.info(STREAMING_DISCONNECTING);
|
|
117
|
-
|
|
118
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
119
|
-
connectPushRetryBackoff.reset();
|
|
120
|
-
|
|
121
|
-
stopWorkers();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
|
|
125
|
-
function stopWorkers() {
|
|
126
|
-
splitsUpdateWorker.backoff.reset();
|
|
127
|
-
segmentsUpdateWorker.backoff.reset();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
pushEmitter.on(PUSH_SUBSYSTEM_DOWN, stopWorkers);
|
|
131
|
-
|
|
132
|
-
// restart backoff retry counter once push is connected
|
|
133
|
-
pushEmitter.on(PUSH_SUBSYSTEM_UP, () => { connectPushRetryBackoff.reset(); });
|
|
134
|
-
|
|
135
|
-
/** Fallbacking without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
|
|
136
|
-
|
|
137
|
-
pushEmitter.on(PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
|
|
138
|
-
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
139
|
-
disconnectPush();
|
|
140
|
-
pushEmitter.emit(PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
/** Fallbacking with retry due to recoverable SSE and Authentication errors */
|
|
144
|
-
|
|
145
|
-
pushEmitter.on(PUSH_RETRYABLE_ERROR, function handleRetryableError() { // HTTP or network error in SSE connection
|
|
146
|
-
// SSE connection is closed to avoid repeated errors due to retries
|
|
147
|
-
sseClient.close();
|
|
148
|
-
|
|
149
|
-
// retry streaming reconnect with backoff algorithm
|
|
150
|
-
let delayInMillis = connectPushRetryBackoff.scheduleCall();
|
|
151
|
-
|
|
152
|
-
log.info(STREAMING_RECONNECT, [delayInMillis / 1000]);
|
|
153
|
-
|
|
154
|
-
pushEmitter.emit(PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
158
|
-
|
|
159
|
-
pushEmitter.on(SPLIT_KILL, splitsUpdateWorker.killSplit);
|
|
160
|
-
pushEmitter.on(SPLIT_UPDATE, splitsUpdateWorker.put);
|
|
161
|
-
// [Only for server-side]
|
|
162
|
-
pushEmitter.on(SEGMENT_UPDATE, segmentsUpdateWorker.put);
|
|
163
|
-
|
|
164
|
-
return objectAssign(
|
|
165
|
-
// Expose Event Emitter functionality and Event constants
|
|
166
|
-
Object.create(pushEmitter),
|
|
167
|
-
{
|
|
168
|
-
// Expose functionality for starting and stoping push mode:
|
|
169
|
-
stop: disconnectPush, // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which start polling.
|
|
170
|
-
|
|
171
|
-
start() {
|
|
172
|
-
// Run in next event-loop cycle as in browser
|
|
173
|
-
setTimeout(connectPush);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
}
|