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

View File

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