mirror of
https://github.com/iconify/iconify.git
synced 2025-01-07 15:44:05 +00:00
Remove unused functionality in redundancy
This commit is contained in:
parent
42d8abf1db
commit
abf29e3cd4
@ -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)
|
* Resource to rotate (usually hostname or partial URL)
|
||||||
*/
|
*/
|
||||||
@ -30,8 +9,8 @@ export type RedundancyResource = string;
|
|||||||
export interface RedundancyConfig {
|
export interface RedundancyConfig {
|
||||||
resources: RedundancyResource[]; // Resources to rotate
|
resources: RedundancyResource[]; // Resources to rotate
|
||||||
index: number; // Start index
|
index: number; // Start index
|
||||||
timeout: number | TimeoutCallback; // Timeout for error (full timeout = timeout + resources.length * rotate)
|
timeout: number; // Timeout for error (full timeout = timeout + resources.length * rotate)
|
||||||
rotate: number | RotationTimeoutCallback; // Timeout for one query
|
rotate: number; // Timeout for one query
|
||||||
random: boolean; // True if order should be randomised
|
random: boolean; // True if order should be randomised
|
||||||
dataAfterTimeout: boolean; // True if data can be sent after timeout
|
dataAfterTimeout: boolean; // True if data can be sent after timeout
|
||||||
}
|
}
|
||||||
|
@ -117,10 +117,6 @@ export function initRedundancy(cfg: Partial<RedundancyConfig>): Redundancy {
|
|||||||
if (doneCallback) {
|
if (doneCallback) {
|
||||||
doneCallback(data, error);
|
doneCallback(data, error);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
(newIndex) => {
|
|
||||||
// Update start index
|
|
||||||
config.index = newIndex;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
queries.push(query);
|
queries.push(query);
|
||||||
|
@ -76,8 +76,7 @@ export function sendQuery(
|
|||||||
config: RedundancyConfig,
|
config: RedundancyConfig,
|
||||||
payload: unknown,
|
payload: unknown,
|
||||||
query: QueryModuleCallback,
|
query: QueryModuleCallback,
|
||||||
done?: QueryDoneCallback,
|
done?: QueryDoneCallback
|
||||||
success?: QueryUpdateIndexCallback
|
|
||||||
): GetQueryStatus {
|
): GetQueryStatus {
|
||||||
// Get number of resources
|
// Get number of resources
|
||||||
const resourcesCount = config.resources.length;
|
const resourcesCount = config.resources.length;
|
||||||
@ -270,11 +269,11 @@ export function sendQuery(
|
|||||||
resetTimer();
|
resetTimer();
|
||||||
clearQueue();
|
clearQueue();
|
||||||
|
|
||||||
// Update index in Redundancy
|
// Update index in configuration
|
||||||
if (success && !config.random) {
|
if (!config.random) {
|
||||||
const index = config.resources.indexOf(item.resource);
|
const index = config.resources.indexOf(item.resource);
|
||||||
if (index !== -1 && index !== config.index) {
|
if (index !== -1 && index !== config.index) {
|
||||||
success(index);
|
config.index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,22 +301,16 @@ export function sendQuery(
|
|||||||
if (resource === void 0) {
|
if (resource === void 0) {
|
||||||
// Nothing to execute: wait for final timeout before failing
|
// Nothing to execute: wait for final timeout before failing
|
||||||
if (queue.length) {
|
if (queue.length) {
|
||||||
const timeout: number =
|
// Last timeout before failing to allow late response
|
||||||
typeof config.timeout === 'function'
|
timer = setTimeout(() => {
|
||||||
? config.timeout(startTime)
|
resetTimer();
|
||||||
: config.timeout;
|
if (status === 'pending') {
|
||||||
if (timeout) {
|
// Clear queue
|
||||||
// Last timeout before failing to allow late response
|
clearQueue();
|
||||||
timer = setTimeout(() => {
|
failQuery();
|
||||||
resetTimer();
|
}
|
||||||
if (status === 'pending') {
|
}, config.timeout);
|
||||||
// Clear queue
|
return;
|
||||||
clearQueue();
|
|
||||||
failQuery();
|
|
||||||
}
|
|
||||||
}, timeout);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail
|
// Fail
|
||||||
@ -341,14 +334,8 @@ export function sendQuery(
|
|||||||
// Bump next index
|
// Bump next index
|
||||||
queriesSent++;
|
queriesSent++;
|
||||||
|
|
||||||
// Get timeout for next item
|
|
||||||
const timeout: number =
|
|
||||||
typeof config.rotate === 'function'
|
|
||||||
? config.rotate(queriesSent, startTime)
|
|
||||||
: config.rotate;
|
|
||||||
|
|
||||||
// Create timer
|
// Create timer
|
||||||
timer = setTimeout(execNext, timeout);
|
timer = setTimeout(execNext, config.rotate);
|
||||||
|
|
||||||
// Execute it
|
// Execute it
|
||||||
query(resource, payload, item);
|
query(resource, payload, item);
|
||||||
|
@ -68,9 +68,6 @@ describe('Multiple resources', () => {
|
|||||||
expect(diff).toBeLessThan(50);
|
expect(diff).toBeLessThan(50);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
},
|
|
||||||
() => {
|
|
||||||
done('This should not have been called');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -101,7 +98,6 @@ describe('Multiple resources', () => {
|
|||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
let sentQuery = 0;
|
let sentQuery = 0;
|
||||||
let itemAborted = false;
|
let itemAborted = false;
|
||||||
let parentUpdated = false;
|
|
||||||
|
|
||||||
// Send query
|
// Send query
|
||||||
const getStatus = sendQuery(
|
const getStatus = sendQuery(
|
||||||
@ -174,20 +170,12 @@ describe('Multiple resources', () => {
|
|||||||
expect(status.queriesSent).toEqual(2);
|
expect(status.queriesSent).toEqual(2);
|
||||||
expect(status.queriesPending).toEqual(0);
|
expect(status.queriesPending).toEqual(0);
|
||||||
|
|
||||||
// Parent should have been updated
|
|
||||||
expect(parentUpdated).toEqual(true);
|
|
||||||
|
|
||||||
// Delay between first and second queries
|
// Delay between first and second queries
|
||||||
const diff = Date.now() - startTime;
|
const diff = Date.now() - startTime;
|
||||||
expect(diff).toBeGreaterThan(50);
|
expect(diff).toBeGreaterThan(50);
|
||||||
expect(diff).toBeLessThan(150);
|
expect(diff).toBeLessThan(150);
|
||||||
|
|
||||||
done();
|
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);
|
expect(diff).toBeLessThan(120);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
},
|
|
||||||
() => {
|
|
||||||
done('This should have never been called');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -385,9 +370,6 @@ describe('Multiple resources', () => {
|
|||||||
expect(diff).toBeLessThan(120);
|
expect(diff).toBeLessThan(120);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
},
|
|
||||||
() => {
|
|
||||||
done('This should have never been called');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -448,9 +430,6 @@ describe('Multiple resources', () => {
|
|||||||
expect(diff).toBeLessThan(170);
|
expect(diff).toBeLessThan(170);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
},
|
|
||||||
() => {
|
|
||||||
done('This should have never been called');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user