Skip to content

Commit

Permalink
fix: update use-get-health.ts (langflow-ai#2553)
Browse files Browse the repository at this point in the history
* update getHealth function to use options param

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and ogabrielluiz committed Jul 9, 2024
1 parent 8057156 commit 1fae5ad
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/frontend/src/controllers/API/queries/health/use-get-health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,24 @@ interface getHealthResponse {
export const useGetHealthQuery: useQueryFunctionType<
undefined,
getHealthResponse
> = (_, onFetch) => {
> = (_, options) => {
const { query } = UseRequestProcessor();

const responseFn = (data: getHealthResponse) => {
if (!onFetch) return data;
if (typeof onFetch === "function") return onFetch(data);
switch (onFetch) {
default:
return data;
}
};

/**
* Fetches the health status of the API.
*
* @returns {Promise<AxiosResponse<TransactionsResponse>>} A promise that resolves to an AxiosResponse containing the health status.
*/
async function getHealthFn() {
return await api.get("/health_check");
return (await api.get("/health_check")).data;
// Health is the only endpoint that doesn't require /api/v1
}

const queryResult = query(
["useGetHealthQuery"],
async () => {
const result = await getHealthFn();
return responseFn(result.data);
},
{
placeholderData: keepPreviousData,
refetchInterval: 20000,
},
);
const queryResult = query(["useGetHealthQuery"], getHealthFn, {
placeholderData: keepPreviousData,
refetchInterval: 20000,
...options,
});

return queryResult;
};

0 comments on commit 1fae5ad

Please sign in to comment.