-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsplitExistence.ts
More file actions
19 lines (17 loc) · 1021 Bytes
/
splitExistence.ts
File metadata and controls
19 lines (17 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { SPLIT_NOT_FOUND } from '../labels';
import { IReadinessManager } from '../../readiness/types';
import { ILogger } from '../../logger/types';
import { WARN_NOT_EXISTENT_SPLIT } from '../../logger/constants';
/**
* This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
* But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a split twice.
*/
export function validateSplitExistence(log: ILogger, readinessManager: IReadinessManager, splitName: string, labelOrSplitObj: any, method: string): boolean {
if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
if (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj == null) {
log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
return false;
}
}
return true;
}