2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

Remove unused functionality in redundancy

This commit is contained in:
Vjacheslav Trushkin 2022-01-25 19:55:54 +02:00
parent 42d8abf1db
commit abf29e3cd4
4 changed files with 17 additions and 76 deletions

View File

@ -1,24 +1,3 @@
/**
* Callback for "timeout" configuration property.
* Returns number of milliseconds to wait before failing query, while there are pending resources.
*/
export interface TimeoutCallback {
(
startTime: number // Start time
): number;
}
/**
* Callback for "rotate" configuration property.
* Returns number of milliseconds to wait before trying next resource.
*/
export interface RotationTimeoutCallback {
(
queriesSent: number, // Number of queries sent, starts with 1 for timeout after first resource
startTime: number // Query start time
): number;
}
/**
* Resource to rotate (usually hostname or partial URL)
*/
@ -30,8 +9,8 @@ export type RedundancyResource = string;
export interface RedundancyConfig {
resources: RedundancyResource[]; // Resources to rotate
index: number; // Start index
timeout: number | TimeoutCallback; // Timeout for error (full timeout = timeout + resources.length * rotate)
rotate: number | RotationTimeoutCallback; // Timeout for one query
timeout: number; // Timeout for error (full timeout = timeout + resources.length * rotate)
rotate: number; // Timeout for one query
random: boolean; // True if order should be randomised
dataAfterTimeout: boolean; // True if data can be sent after timeout
}

View File

@ -117,10 +117,6 @@ export function initRedundancy(cfg: Partial<RedundancyConfig>): Redundancy {
if (doneCallback) {
doneCallback(data, error);
}
},
(newIndex) => {
// Update start index
config.index = newIndex;
}
);
queries.push(query);

View File

@ -76,8 +76,7 @@ export function sendQuery(
config: RedundancyConfig,
payload: unknown,
query: QueryModuleCallback,
done?: QueryDoneCallback,
success?: QueryUpdateIndexCallback
done?: QueryDoneCallback
): GetQueryStatus {
// Get number of resources
const resourcesCount = config.resources.length;
@ -270,11 +269,11 @@ export function sendQuery(
resetTimer();
clearQueue();
// Update index in Redundancy
if (success && !config.random) {
// Update index in configuration
if (!config.random) {
const index = config.resources.indexOf(item.resource);
if (index !== -1 && index !== config.index) {
success(index);
config.index = index;
}
}
@ -302,22 +301,16 @@ export function sendQuery(
if (resource === void 0) {
// Nothing to execute: wait for final timeout before failing
if (queue.length) {
const timeout: number =
typeof config.timeout === 'function'
? config.timeout(startTime)
: config.timeout;
if (timeout) {
// Last timeout before failing to allow late response
timer = setTimeout(() => {
resetTimer();
if (status === 'pending') {
// Clear queue
clearQueue();
failQuery();
}
}, timeout);
return;
}
// Last timeout before failing to allow late response
timer = setTimeout(() => {
resetTimer();
if (status === 'pending') {
// Clear queue
clearQueue();
failQuery();
}
}, config.timeout);
return;
}
// Fail
@ -341,14 +334,8 @@ export function sendQuery(
// Bump next index
queriesSent++;
// Get timeout for next item
const timeout: number =
typeof config.rotate === 'function'
? config.rotate(queriesSent, startTime)
: config.rotate;
// Create timer
timer = setTimeout(execNext, timeout);
timer = setTimeout(execNext, config.rotate);
// Execute it
query(resource, payload, item);

View File

@ -68,9 +68,6 @@ describe('Multiple resources', () => {
expect(diff).toBeLessThan(50);
done();
},
() => {
done('This should not have been called');
}
);
@ -101,7 +98,6 @@ describe('Multiple resources', () => {
const startTime = Date.now();
let sentQuery = 0;
let itemAborted = false;
let parentUpdated = false;
// Send query
const getStatus = sendQuery(
@ -174,20 +170,12 @@ describe('Multiple resources', () => {
expect(status.queriesSent).toEqual(2);
expect(status.queriesPending).toEqual(0);
// Parent should have been updated
expect(parentUpdated).toEqual(true);
// Delay between first and second queries
const diff = Date.now() - startTime;
expect(diff).toBeGreaterThan(50);
expect(diff).toBeLessThan(150);
done();
},
(newIndex) => {
// Start index should be updated to 1
expect(newIndex).toEqual(1);
parentUpdated = true;
}
);
@ -300,9 +288,6 @@ describe('Multiple resources', () => {
expect(diff).toBeLessThan(120);
done();
},
() => {
done('This should have never been called');
}
);
@ -385,9 +370,6 @@ describe('Multiple resources', () => {
expect(diff).toBeLessThan(120);
done();
},
() => {
done('This should have never been called');
}
);
@ -448,9 +430,6 @@ describe('Multiple resources', () => {
expect(diff).toBeLessThan(170);
done();
},
() => {
done('This should have never been called');
}
);