fix health bug

This commit is contained in:
Matt Hill
2023-04-03 16:56:12 -06:00
parent fa53436ab2
commit c8516933d6

View File

@@ -37,28 +37,23 @@ async function timeoutHealth(
* The stop function is used to stop the health check. * The stop function is used to stop the health check.
*/ */
const defaultParams = {
defaultIntervalS: 60,
defaultTimeoutS: 10,
defaultDelayS: 10,
};
export default function healthRunner( export default function healthRunner(
name: string, name: string,
fn: HealthCheck, fn: HealthCheck,
params = defaultParams
) { ) {
return { return {
/** \ /**
* All values in seconds * All values in seconds. Defaults):
* defaults: *
* interval: 60s * interval: 60s
*
* timeout: 10s * timeout: 10s
*
* delay: 10s * delay: 10s
*/ */
create( create(
effects: Types.Effects, effects: Types.Effects,
{ interval = 60, timeout = 10, delay = 10 } = {} options = { interval: 60, timeout: 10, delay: 10 }
) { ) {
let running: any; let running: any;
function startFn() { function startFn() {
@@ -66,7 +61,7 @@ export default function healthRunner(
setTimeout(() => { setTimeout(() => {
running = setInterval(async () => { running = setInterval(async () => {
const result = await Promise.race([ const result = await Promise.race([
timeoutHealth(effects, timeout * 1000), timeoutHealth(effects, options.timeout * 1000),
fn(effects, 123), fn(effects, 123),
]).catch((e) => { ]).catch((e) => {
return { failure: safelyStringify(e) }; return { failure: safelyStringify(e) };
@@ -75,8 +70,8 @@ export default function healthRunner(
name, name,
result, result,
}); });
}, interval * 1000); }, options.interval * 1000);
}, delay * 1000); }, options.delay * 1000);
} }
const self = { const self = {