mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
formatting
This commit is contained in:
@@ -6,8 +6,10 @@ export const checkWebUrl: (
|
||||
(url) => {
|
||||
return async (effects, duration) => {
|
||||
let errorValue;
|
||||
// deno-lint-ignore no-cond-assign
|
||||
if (errorValue = guardDurationAboveMinimum({ duration, minimumTime: 5000 })) return errorValue;
|
||||
if (
|
||||
// deno-lint-ignore no-cond-assign
|
||||
errorValue = guardDurationAboveMinimum({ duration, minimumTime: 5000 })
|
||||
) return errorValue;
|
||||
|
||||
return await effects.fetch(url)
|
||||
.then((_) => ok)
|
||||
@@ -20,25 +22,27 @@ export const checkWebUrl: (
|
||||
};
|
||||
};
|
||||
|
||||
export const runHealthScript = ({command, args}: { command: string, args: string[] }) => async (effects: Effects, _duration: number): Promise<ResultType<null | void>> => {
|
||||
const res = await effects.runCommand({ command, args })
|
||||
if ('result' in res){
|
||||
return { result: null }
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
}
|
||||
export const runHealthScript =
|
||||
({ command, args }: { command: string; args: string[] }) =>
|
||||
async (
|
||||
effects: Effects,
|
||||
_duration: number,
|
||||
): Promise<ResultType<null | void>> => {
|
||||
const res = await effects.runCommand({ command, args });
|
||||
if ("result" in res) {
|
||||
return { result: null };
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
// Ensure the starting duration is pass a minimum
|
||||
export const guardDurationAboveMinimum = (
|
||||
input: { duration: number; minimumTime: number },
|
||||
) =>
|
||||
(input.duration <= input.minimumTime)
|
||||
? errorCode(60, "Starting")
|
||||
: null;
|
||||
) => (input.duration <= input.minimumTime) ? errorCode(60, "Starting") : null;
|
||||
|
||||
export const catchError = (effects: Effects) => (e: unknown) => {
|
||||
if (isKnownError(e)) return e
|
||||
if (isKnownError(e)) return e;
|
||||
effects.error(`Health check failed: ${e}`);
|
||||
return error( "Error while running health check" );
|
||||
return error("Error while running health check");
|
||||
};
|
||||
|
||||
4
util.ts
4
util.ts
@@ -22,5 +22,5 @@ export const errorCode = (code: number, error: string) => ({
|
||||
export const error = (error: string) => ({ error });
|
||||
export const ok = { result: null };
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export const isKnownError = (e: unknown): e is T.KnownError => e instanceof Object && ('error' in e || "error-code" in e)
|
||||
export const isKnownError = (e: unknown): e is T.KnownError =>
|
||||
e instanceof Object && ("error" in e || "error-code" in e);
|
||||
|
||||
Reference in New Issue
Block a user