feat: manual health check

This commit is contained in:
Nicolas Meienberger
2025-09-27 11:09:19 +02:00
parent 082192f38a
commit 7154dcdbac
9 changed files with 142 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ import {
getContainersUsingVolume,
mountVolume,
unmountVolume,
healthCheckVolume,
} from "../sdk.gen";
import { queryOptions, type UseMutationOptions, type DefaultError } from "@tanstack/react-query";
import type {
@@ -29,6 +30,8 @@ import type {
MountVolumeResponse,
UnmountVolumeData,
UnmountVolumeResponse,
HealthCheckVolumeData,
HealthCheckVolumeResponse,
} from "../types.gen";
import { client as _heyApiClient } from "../client.gen";
@@ -326,3 +329,43 @@ export const unmountVolumeMutation = (
};
return mutationOptions;
};
export const healthCheckVolumeQueryKey = (options: Options<HealthCheckVolumeData>) =>
createQueryKey("healthCheckVolume", options);
/**
* Perform a health check on a volume
*/
export const healthCheckVolumeOptions = (options: Options<HealthCheckVolumeData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await healthCheckVolume({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: healthCheckVolumeQueryKey(options),
});
};
/**
* Perform a health check on a volume
*/
export const healthCheckVolumeMutation = (
options?: Partial<Options<HealthCheckVolumeData>>,
): UseMutationOptions<HealthCheckVolumeResponse, DefaultError, Options<HealthCheckVolumeData>> => {
const mutationOptions: UseMutationOptions<HealthCheckVolumeResponse, DefaultError, Options<HealthCheckVolumeData>> = {
mutationFn: async (localOptions) => {
const { data } = await healthCheckVolume({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};