diff --git a/lib/health/HealthCheck.ts b/lib/health/HealthCheck.ts index 67c2245..d787869 100644 --- a/lib/health/HealthCheck.ts +++ b/lib/health/HealthCheck.ts @@ -15,7 +15,6 @@ export function healthCheck(o: { }) { new Promise(async () => { let currentValue: TriggerInput = { - lastResult: null, hadSuccess: false, } const getCurrentValue = () => currentValue @@ -33,9 +32,9 @@ export function healthCheck(o: { message, }) currentValue.hadSuccess = true - currentValue.lastResult = "success" + currentValue.lastResult = "passing" } catch (_) { - currentValue.lastResult = "failure" + currentValue.lastResult = "failing" } } }) diff --git a/lib/health/trigger/TriggerInput.ts b/lib/health/trigger/TriggerInput.ts index 8885c70..6c07c71 100644 --- a/lib/health/trigger/TriggerInput.ts +++ b/lib/health/trigger/TriggerInput.ts @@ -1,4 +1,6 @@ +import { HealthStatus } from "../../types" + export type TriggerInput = { - lastResult?: "success" | "failure" | null + lastResult?: HealthStatus hadSuccess?: boolean } diff --git a/lib/health/trigger/changeOnFirstSuccess.ts b/lib/health/trigger/changeOnFirstSuccess.ts index 03d1cd5..010d2c6 100644 --- a/lib/health/trigger/changeOnFirstSuccess.ts +++ b/lib/health/trigger/changeOnFirstSuccess.ts @@ -12,7 +12,7 @@ export function changeOnFirstSuccess(o: { beforeFirstSuccess.next() for ( let res = await beforeFirstSuccess.next(); - currentValue?.lastResult !== "success" && !res.done; + currentValue?.lastResult !== "passing" && !res.done; res = await beforeFirstSuccess.next() ) { yield diff --git a/lib/mainFn/Daemons.ts b/lib/mainFn/Daemons.ts index 935c956..91aedb4 100644 --- a/lib/mainFn/Daemons.ts +++ b/lib/mainFn/Daemons.ts @@ -1,4 +1,4 @@ -import { HealthReceipt, ReadyProof } from "../health" +import { HealthReceipt, ReadyProof, TriggerInput } from "../health" import { CheckResult } from "../health/checkFns" import { Trigger } from "../health/trigger" import { defaultTrigger } from "../health/trigger/defaultTrigger" @@ -82,21 +82,26 @@ export class Daemons { const { command } = daemon const child = effects.runDaemon(command) - let currentInput = {} + let currentInput: TriggerInput = {} const getCurrentInput = () => currentInput const trigger = (daemon.ready.trigger ?? defaultTrigger)( getCurrentInput, ) - for ( - let res = await trigger.next(); - !res.done; - res = await trigger.next() - ) { - const response = await daemon.ready.fn() - if (response.status === "passing") { - return child + return new Promise(async (resolve) => { + for ( + let res = await trigger.next(); + !res.done; + res = await trigger.next() + ) { + const response = await daemon.ready.fn() + currentInput.lastResult = response.status || null + if (!currentInput.hadSuccess && response.status === "passing") { + currentInput.hadSuccess = true + resolve(child) + } } - } + resolve(child) + }) return child }) } diff --git a/lib/test/output.test.ts b/lib/test/output.test.ts index 6cb0cc2..1e629b2 100644 --- a/lib/test/output.test.ts +++ b/lib/test/output.test.ts @@ -6,6 +6,7 @@ import { } from "../config/configTypes" import { deepMerge } from "../util" import { InputSpec, matchInputSpec } from "./output" +import * as _I from "../index" export type IfEquals = (() => G extends T ? 1