mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
update health defaults
This commit is contained in:
@@ -36,20 +36,38 @@ async function timeoutHealth(
|
|||||||
* then from there we need a start().
|
* then from there we need a start().
|
||||||
* 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,
|
||||||
{ defaultIntervalS = 60 } = {}
|
params = defaultParams
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
create(effects: Types.Effects, defaultIntervalCreatedS = defaultIntervalS) {
|
/** \
|
||||||
|
* All values in seconds
|
||||||
|
* defaults:
|
||||||
|
* interval: 60s
|
||||||
|
* timeout: 10s
|
||||||
|
* delay: 10s
|
||||||
|
*/
|
||||||
|
create(effects: Types.Effects, {
|
||||||
|
interval = 60,
|
||||||
|
timeout = 10,
|
||||||
|
delay = 10,
|
||||||
|
} = {}) {
|
||||||
let running: any;
|
let running: any;
|
||||||
function startFn(intervalS: number, timeoutS: number, delayS: number) {
|
function startFn() {
|
||||||
clearInterval(running);
|
clearInterval(running);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
running = setInterval(async () => {
|
running = setInterval(async () => {
|
||||||
const result = await Promise.race([
|
const result = await Promise.race([
|
||||||
timeoutHealth(effects, timeoutS * 1000),
|
timeoutHealth(effects, timeout * 1000),
|
||||||
fn(effects, 123),
|
fn(effects, 123),
|
||||||
]).catch((e) => {
|
]).catch((e) => {
|
||||||
return { failure: safelyStringify(e) };
|
return { failure: safelyStringify(e) };
|
||||||
@@ -58,8 +76,8 @@ export default function healthRunner(
|
|||||||
name,
|
name,
|
||||||
result,
|
result,
|
||||||
});
|
});
|
||||||
}, intervalS * 1000);
|
}, interval * 1000);
|
||||||
}, delayS * 1000);
|
}, delay * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const self = {
|
const self = {
|
||||||
@@ -67,12 +85,8 @@ export default function healthRunner(
|
|||||||
clearInterval(running);
|
clearInterval(running);
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
start({
|
start() {
|
||||||
intervalS = defaultIntervalCreatedS,
|
startFn();
|
||||||
timeoutS = 10,
|
|
||||||
delayS = 0,
|
|
||||||
} = {}) {
|
|
||||||
startFn(intervalS, timeoutS, delayS);
|
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
5884
package-lock.json
generated
5884
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user