2020-04-23 01:54:27 +02:00
|
|
|
import { SDK_API_PATH } from 'ui';
|
2020-03-17 16:21:26 +01:00
|
|
|
import { useEffect } from 'react';
|
2020-04-23 01:54:27 +02:00
|
|
|
|
2020-03-17 16:21:26 +01:00
|
|
|
import fetchWithTimeout from 'util/fetch';
|
|
|
|
|
|
|
|
const STATUS_TIMEOUT_LIMIT = 10000;
|
|
|
|
export const STATUS_OK = 'ok';
|
|
|
|
export const STATUS_DEGRADED = 'degraded';
|
2020-03-26 21:17:41 +01:00
|
|
|
export const STATUS_FAILING = 'failing';
|
2020-03-17 16:21:26 +01:00
|
|
|
export const STATUS_DOWN = 'down';
|
|
|
|
|
|
|
|
export function useDegradedPerformance(onDegradedPerformanceCallback) {
|
|
|
|
useEffect(() => {
|
2020-04-23 01:54:27 +02:00
|
|
|
fetchWithTimeout(STATUS_TIMEOUT_LIMIT, fetch(`${SDK_API_PATH}/status`))
|
2020-03-17 16:21:26 +01:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(status => {
|
2020-03-26 21:17:41 +01:00
|
|
|
if (status.general_state !== STATUS_OK) {
|
|
|
|
onDegradedPerformanceCallback(STATUS_FAILING);
|
2020-03-17 16:21:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2020-03-26 21:17:41 +01:00
|
|
|
onDegradedPerformanceCallback(STATUS_FAILING);
|
2020-03-17 16:21:26 +01:00
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
}
|