mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-04 14:29:47 +00:00
fix health bug
This commit is contained in:
@@ -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 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user