chore: update the healthchecks and HealthCheck

This commit is contained in:
BluJ
2023-05-17 15:04:25 -06:00
parent 600db7377f
commit 0676b67cd3
3 changed files with 41 additions and 4 deletions

View File

@@ -51,6 +51,7 @@ import {
SetInterfaces, SetInterfaces,
setupInterfaces, setupInterfaces,
} from "./interfaces/setupInterfaces" } from "./interfaces/setupInterfaces"
import { successFailure } from "./trigger/successFailure"
// prettier-ignore // prettier-ignore
type AnyNeverCond<T extends any[], Then, Else> = type AnyNeverCond<T extends any[], Then, Else> =
@@ -96,10 +97,12 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
input: Type input: Type
}) => Promise<ActionResult>, }) => Promise<ActionResult>,
) => createAction<Store, Vault, ConfigType, Type>(metaData, fn), ) => createAction<Store, Vault, ConfigType, Type>(metaData, fn),
HealthCheck: {
of: healthCheck,
},
healthCheck: { healthCheck: {
checkPortListening, checkPortListening,
checkWebUrl, checkWebUrl,
of: healthCheck,
runHealthScript, runHealthScript,
}, },
patterns, patterns,
@@ -186,6 +189,7 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
defaultTrigger, defaultTrigger,
cooldownTrigger, cooldownTrigger,
changeOnFirstSuccess, changeOnFirstSuccess,
successFailure,
}, },
Backups: { Backups: {

View File

@@ -1,7 +1,8 @@
import { cooldownTrigger } from "./cooldownTrigger" import { cooldownTrigger } from "./cooldownTrigger"
import { changeOnFirstSuccess } from "./changeOnFirstSuccess" import { changeOnFirstSuccess } from "./changeOnFirstSuccess"
import { successFailure } from "./successFailure"
export const defaultTrigger = changeOnFirstSuccess({ export const defaultTrigger = successFailure({
beforeFirstSuccess: cooldownTrigger(0), duringSuccess: cooldownTrigger(0),
afterFirstSuccess: cooldownTrigger(30000), duringError: cooldownTrigger(30000),
}) })

View File

@@ -0,0 +1,32 @@
import { Trigger } from "."
export function successFailure(o: {
duringSuccess: Trigger
duringError: Trigger
}): Trigger {
return async function* (getInput) {
while (true) {
const beforeSuccess = o.duringSuccess(getInput)
yield
let currentValue = getInput()
beforeSuccess.next()
for (
let res = await beforeSuccess.next();
currentValue?.lastResult !== "passing" && !res.done;
res = await beforeSuccess.next()
) {
yield
currentValue = getInput()
}
const duringError = o.duringError(getInput)
for (
let res = await duringError.next();
currentValue?.lastResult === "passing" && !res.done;
res = await duringError.next()
) {
yield
currentValue = getInput()
}
}
}
}