2026-02-05 21:40:36 +00:00
|
|
|
import Stack from "@mui/material/Stack";
|
2026-02-06 17:24:16 +00:00
|
|
|
import Typography from "@mui/material/Typography";
|
2026-04-25 23:26:34 -04:00
|
|
|
import Box from "@mui/material/Box";
|
2026-02-06 18:56:10 +00:00
|
|
|
import { TableJobs, TableFailedJobs } from "./components/TableJobs";
|
2026-02-05 21:40:36 +00:00
|
|
|
|
|
|
|
|
import { useTheme } from "@mui/material";
|
2026-04-25 23:26:34 -04:00
|
|
|
import { useTranslation, Trans } from "react-i18next";
|
2026-02-05 21:40:36 +00:00
|
|
|
import { useGet, usePost } from "@/Hooks/UseApi";
|
|
|
|
|
import type { QueueData } from "@/Types/Queue";
|
2026-02-06 18:56:10 +00:00
|
|
|
import { Metrics } from "@/Pages/Logs/components/Metrics";
|
2026-02-20 18:13:39 +00:00
|
|
|
import { Button } from "@/Components/inputs";
|
2026-04-25 23:26:34 -04:00
|
|
|
import { EmptyState } from "@/Components/design-elements";
|
2026-05-04 11:59:02 -07:00
|
|
|
import { SPACING } from "@/Utils/Theme/constants";
|
2026-02-05 21:40:36 +00:00
|
|
|
|
2026-02-05 20:23:04 +00:00
|
|
|
export const TabQueue = () => {
|
2026-02-05 21:40:36 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const {
|
|
|
|
|
data: queueData,
|
2026-04-25 23:26:34 -04:00
|
|
|
isLoading,
|
2026-02-05 21:40:36 +00:00
|
|
|
// error,
|
|
|
|
|
refetch,
|
2026-05-04 11:53:12 -07:00
|
|
|
} = useGet<QueueData>("/queue/all-metrics", {}, { refreshInterval: 1000 });
|
2026-02-05 21:40:36 +00:00
|
|
|
|
|
|
|
|
const { post, loading: isFlushing } = usePost();
|
|
|
|
|
|
|
|
|
|
const jobs = queueData?.jobs ?? [];
|
|
|
|
|
const metrics = queueData?.metrics ?? null;
|
2026-04-25 23:26:34 -04:00
|
|
|
const hasNeverRun = !isLoading && metrics !== null && (metrics.totalRuns ?? 0) === 0;
|
|
|
|
|
const noQueueData = !isLoading && metrics === null && jobs.length === 0;
|
|
|
|
|
if (hasNeverRun || noQueueData) {
|
|
|
|
|
return (
|
|
|
|
|
<EmptyState
|
|
|
|
|
fullscreen
|
|
|
|
|
title={t("pages.logs.queueFallback.title")}
|
|
|
|
|
description={t("pages.logs.queueFallback.description")}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-05 21:40:36 +00:00
|
|
|
|
|
|
|
|
const handleFlushQueue = async () => {
|
|
|
|
|
await post("/queue/flush", {});
|
|
|
|
|
refetch();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-04-26 01:55:33 -04:00
|
|
|
<Stack gap={theme.spacing(16)}>
|
2026-02-05 21:40:36 +00:00
|
|
|
<Metrics metrics={metrics} />
|
2026-04-26 01:55:33 -04:00
|
|
|
<Stack gap={theme.spacing(3)}>
|
|
|
|
|
<Stack gap={theme.spacing(1)}>
|
|
|
|
|
<Typography
|
|
|
|
|
variant="eyebrow"
|
2026-05-04 11:59:02 -07:00
|
|
|
color={theme.palette.text.secondary}
|
2026-04-26 01:55:33 -04:00
|
|
|
>
|
|
|
|
|
{t("pages.logs.jobQueue")}
|
|
|
|
|
</Typography>
|
2026-05-04 11:59:02 -07:00
|
|
|
<Typography color={theme.palette.text.secondary}>
|
2026-04-26 01:55:33 -04:00
|
|
|
<Trans
|
|
|
|
|
i18nKey="pages.logs.jobQueueExplainer"
|
|
|
|
|
components={{
|
|
|
|
|
highlight: (
|
|
|
|
|
<Box
|
|
|
|
|
component="span"
|
2026-05-04 11:59:02 -07:00
|
|
|
bgcolor={
|
|
|
|
|
theme.palette.mode === "dark"
|
|
|
|
|
? "rgba(19, 113, 91, 0.18)"
|
|
|
|
|
: "#ECF7F2"
|
|
|
|
|
}
|
|
|
|
|
color={theme.palette.text.primary}
|
|
|
|
|
px={SPACING.SM}
|
|
|
|
|
py={SPACING.XXS}
|
|
|
|
|
borderRadius={theme.shape.borderRadius}
|
2026-04-26 01:55:33 -04:00
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Typography>
|
|
|
|
|
</Stack>
|
|
|
|
|
<TableJobs jobs={jobs} />
|
2026-04-25 23:26:34 -04:00
|
|
|
</Stack>
|
2026-04-26 01:55:33 -04:00
|
|
|
<Stack gap={theme.spacing(3)}>
|
|
|
|
|
<Stack gap={theme.spacing(1)}>
|
|
|
|
|
<Typography
|
|
|
|
|
variant="eyebrow"
|
2026-05-04 11:59:02 -07:00
|
|
|
color={theme.palette.text.secondary}
|
2026-04-26 01:55:33 -04:00
|
|
|
>
|
|
|
|
|
{t("pages.logs.failedJobs")}
|
|
|
|
|
</Typography>
|
2026-05-04 11:59:02 -07:00
|
|
|
<Typography color={theme.palette.text.secondary}>
|
2026-04-26 01:55:33 -04:00
|
|
|
{t("pages.logs.failedJobsExplainer")}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Stack>
|
|
|
|
|
<TableFailedJobs metrics={metrics} />
|
2026-04-25 23:26:34 -04:00
|
|
|
</Stack>
|
2026-02-05 21:40:36 +00:00
|
|
|
<Stack alignItems={"flex-end"}>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
onClick={handleFlushQueue}
|
|
|
|
|
loading={isFlushing}
|
|
|
|
|
>
|
|
|
|
|
{t("common.buttons.flushQueue")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Stack>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
2026-02-05 20:23:04 +00:00
|
|
|
};
|