mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: manual health check
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -25,6 +25,9 @@ import type {
|
||||
UnmountVolumeData,
|
||||
UnmountVolumeResponses,
|
||||
UnmountVolumeErrors,
|
||||
HealthCheckVolumeData,
|
||||
HealthCheckVolumeResponses,
|
||||
HealthCheckVolumeErrors,
|
||||
} from "./types.gen";
|
||||
import { client as _heyApiClient } from "./client.gen";
|
||||
|
||||
@@ -162,3 +165,15 @@ export const unmountVolume = <ThrowOnError extends boolean = false>(
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform a health check on a volume
|
||||
*/
|
||||
export const healthCheckVolume = <ThrowOnError extends boolean = false>(
|
||||
options: Options<HealthCheckVolumeData, ThrowOnError>,
|
||||
) => {
|
||||
return (options.client ?? _heyApiClient).post<HealthCheckVolumeResponses, HealthCheckVolumeErrors, ThrowOnError>({
|
||||
url: "/api/v1/volumes/{name}/health-check",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -438,6 +438,34 @@ export type UnmountVolumeResponses = {
|
||||
|
||||
export type UnmountVolumeResponse = UnmountVolumeResponses[keyof UnmountVolumeResponses];
|
||||
|
||||
export type HealthCheckVolumeData = {
|
||||
body?: never;
|
||||
path: {
|
||||
name: string;
|
||||
};
|
||||
query?: never;
|
||||
url: "/api/v1/volumes/{name}/health-check";
|
||||
};
|
||||
|
||||
export type HealthCheckVolumeErrors = {
|
||||
/**
|
||||
* Volume not found
|
||||
*/
|
||||
404: unknown;
|
||||
};
|
||||
|
||||
export type HealthCheckVolumeResponses = {
|
||||
/**
|
||||
* Volume health check result
|
||||
*/
|
||||
200: {
|
||||
status: "error" | "mounted" | "unmounted";
|
||||
error?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type HealthCheckVolumeResponse = HealthCheckVolumeResponses[keyof HealthCheckVolumeResponses];
|
||||
|
||||
export type ClientOptions = {
|
||||
baseUrl: "http://localhost:3000" | (string & {});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user