Add Healthcheck Result type
Summary: Adds a type for the return type of runHealthchecks() Reviewed By: passy Differential Revision: D18474919 fbshipit-source-id: b86968088d61d9d2d31815b4c725396cc05d8ca5
This commit is contained in:
committed by
Facebook Github Bot
parent
ad64b257f6
commit
0914deda2d
@@ -34,6 +34,18 @@ type Healthcheck = {
|
||||
}>;
|
||||
};
|
||||
|
||||
type CategoryResult = [
|
||||
string,
|
||||
{
|
||||
label: string;
|
||||
results: Array<{
|
||||
label: string;
|
||||
isRequired: boolean;
|
||||
result: {hasProblem: boolean};
|
||||
}>;
|
||||
},
|
||||
];
|
||||
|
||||
export function getHealthchecks(): Healthchecks {
|
||||
return {
|
||||
common: {
|
||||
@@ -112,32 +124,36 @@ export function getHealthchecks(): Healthchecks {
|
||||
};
|
||||
}
|
||||
|
||||
export async function runHealthchecks() {
|
||||
export async function runHealthchecks(): Promise<Array<CategoryResult>> {
|
||||
const environmentInfo = await getEnvInfo();
|
||||
const healthchecks = getHealthchecks();
|
||||
const results = await Promise.all(
|
||||
Object.entries(healthchecks).map(async ([key, category]) => [
|
||||
key,
|
||||
category
|
||||
? {
|
||||
label: category.label,
|
||||
results: await Promise.all(
|
||||
category.healthchecks.map(async ({label, run, isRequired}) => ({
|
||||
label,
|
||||
isRequired: isRequired ?? true,
|
||||
result: await run(environmentInfo).catch(e => {
|
||||
console.error(e);
|
||||
// TODO Improve result type to be: OK | Problem(message, fix...)
|
||||
return {
|
||||
hasProblem: true,
|
||||
};
|
||||
}),
|
||||
})),
|
||||
),
|
||||
}
|
||||
: {},
|
||||
]),
|
||||
);
|
||||
const healthchecks: Healthchecks = getHealthchecks();
|
||||
const results: Array<CategoryResult> = (await Promise.all(
|
||||
Object.entries(healthchecks).map(async ([key, category]) => {
|
||||
if (!category) {
|
||||
return null;
|
||||
}
|
||||
const categoryResult: CategoryResult = [
|
||||
key,
|
||||
{
|
||||
label: category.label,
|
||||
results: await Promise.all(
|
||||
category.healthchecks.map(async ({label, run, isRequired}) => ({
|
||||
label,
|
||||
isRequired: isRequired ?? true,
|
||||
result: await run(environmentInfo).catch(e => {
|
||||
console.error(e);
|
||||
// TODO Improve result type to be: OK | Problem(message, fix...)
|
||||
return {
|
||||
hasProblem: true,
|
||||
};
|
||||
}),
|
||||
})),
|
||||
),
|
||||
},
|
||||
];
|
||||
return categoryResult;
|
||||
}),
|
||||
)).filter(notNull);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -146,3 +162,7 @@ async function commandSucceeds(command: string): Promise<boolean> {
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
||||
export function notNull<T>(x: T | null | undefined): x is T {
|
||||
return x !== null && x !== undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user