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

@@ -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()
}
}
}
}