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:
John Knox
2019-11-13 08:41:03 -08:00
committed by Facebook Github Bot
parent ad64b257f6
commit 0914deda2d

View File

@@ -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,14 +124,17 @@ 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]) => [
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,
category
? {
{
label: category.label,
results: await Promise.all(
category.healthchecks.map(async ({label, run, isRequired}) => ({
@@ -134,10 +149,11 @@ export async function runHealthchecks() {
}),
})),
),
}
: {},
]),
);
},
];
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;
}