From c82be822b0020e88b6cdffd498523c960f992bcb Mon Sep 17 00:00:00 2001 From: Samir Kamal <1954121+skamril@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:29:59 +0100 Subject: [PATCH] feat(ui-tasks): auto refresh launcher metrics --- .../src/components/App/Tasks/JobTableView.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/webapp/src/components/App/Tasks/JobTableView.tsx b/webapp/src/components/App/Tasks/JobTableView.tsx index 1381489764..506c95762e 100644 --- a/webapp/src/components/App/Tasks/JobTableView.tsx +++ b/webapp/src/components/App/Tasks/JobTableView.tsx @@ -31,6 +31,7 @@ import usePromiseWithSnackbarError from "../../../hooks/usePromiseWithSnackbarEr import { getLauncherMetrics } from "../../../services/api/study"; import LinearProgressWithLabel from "../../common/LinearProgressWithLabel"; import UsePromiseCond from "../../common/utils/UsePromiseCond"; +import { useInterval } from "react-use"; interface PropType { content: TaskView[]; @@ -46,13 +47,10 @@ function JobTableView(props: PropType) { useState(false); const [currentContent, setCurrentContent] = useState(content); - const laucherMetrics = usePromiseWithSnackbarError( - () => getLauncherMetrics(), - { - errorMessage: t("study.error.launchLoad"), - deps: [], - }, - ); + const launcherMetrics = usePromiseWithSnackbarError(getLauncherMetrics, { + errorMessage: t("study.error.launchLoad"), + deps: [], + }); const applyFilter = useCallback( (taskList: TaskView[]) => { @@ -91,6 +89,9 @@ function JobTableView(props: PropType) { setCurrentContent(applyFilter(content)); }, [content, applyFilter]); + // Refresh launcher metrics every minute + useInterval(launcherMetrics.reload, 60_000); + return ( ( <> {t("study.allocatedCpuRate")} @@ -152,7 +154,7 @@ function JobTableView(props: PropType) { color="primary" onClick={() => { refresh(); - laucherMetrics.reload(); + launcherMetrics.reload(); }} variant="outlined" >