From 80a808048340f7f5e95e71c4ee649fdae7c8c565 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 9 Mar 2025 13:22:18 +0000 Subject: feat: Move background jobs with the admin actions. Fixes #1083 --- apps/web/components/admin/BackgroundJobs.tsx | 257 +++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 apps/web/components/admin/BackgroundJobs.tsx (limited to 'apps/web/components/admin/BackgroundJobs.tsx') diff --git a/apps/web/components/admin/BackgroundJobs.tsx b/apps/web/components/admin/BackgroundJobs.tsx new file mode 100644 index 00000000..217e2ad9 --- /dev/null +++ b/apps/web/components/admin/BackgroundJobs.tsx @@ -0,0 +1,257 @@ +"use client"; + +import { ActionButton } from "@/components/ui/action-button"; +import { toast } from "@/components/ui/use-toast"; +import { useTranslation } from "@/lib/i18n/client"; +import { api } from "@/lib/trpc"; +import { keepPreviousData } from "@tanstack/react-query"; + +import LoadingSpinner from "../ui/spinner"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "../ui/table"; + +function AdminActions() { + const { t } = useTranslation(); + const { mutate: recrawlLinks, isPending: isRecrawlPending } = + api.admin.recrawlLinks.useMutation({ + onSuccess: () => { + toast({ + description: "Recrawl enqueued", + }); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: e.message, + }); + }, + }); + + const { mutate: reindexBookmarks, isPending: isReindexPending } = + api.admin.reindexAllBookmarks.useMutation({ + onSuccess: () => { + toast({ + description: "Reindex enqueued", + }); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: e.message, + }); + }, + }); + + const { mutate: reprocessAssetsFixMode, isPending: isReprocessingPending } = + api.admin.reprocessAssetsFixMode.useMutation({ + onSuccess: () => { + toast({ + description: "Reprocessing enqueued", + }); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: e.message, + }); + }, + }); + + const { + mutate: reRunInferenceOnAllBookmarks, + isPending: isInferencePending, + } = api.admin.reRunInferenceOnAllBookmarks.useMutation({ + onSuccess: () => { + toast({ + description: "Inference jobs enqueued", + }); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: e.message, + }); + }, + }); + + const { mutateAsync: tidyAssets, isPending: isTidyAssetsPending } = + api.admin.tidyAssets.useMutation({ + onSuccess: () => { + toast({ + description: "Tidy assets request has been enqueued!", + }); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: e.message, + }); + }, + }); + + return ( +
+ + recrawlLinks({ crawlStatus: "failure", runInference: true }) + } + > + {t("admin.actions.recrawl_failed_links_only")} + + recrawlLinks({ crawlStatus: "all", runInference: true })} + > + {t("admin.actions.recrawl_all_links")} + + + recrawlLinks({ crawlStatus: "all", runInference: false }) + } + > + {t("admin.actions.recrawl_all_links")} ( + {t("admin.actions.without_inference")}) + + + reRunInferenceOnAllBookmarks({ taggingStatus: "failure" }) + } + > + {t("admin.actions.regenerate_ai_tags_for_failed_bookmarks_only")} + + reRunInferenceOnAllBookmarks({ taggingStatus: "all" })} + > + {t("admin.actions.regenerate_ai_tags_for_all_bookmarks")} + + reindexBookmarks()} + > + {t("admin.actions.reindex_all_bookmarks")} + + reprocessAssetsFixMode()} + > + {t("admin.actions.reprocess_assets_fix_mode")} + + tidyAssets()} + > + {t("admin.actions.compact_assets")} + +
+ ); +} + +export default function BackgroundJobs() { + const { t } = useTranslation(); + const { data: serverStats } = api.admin.backgroundJobsStats.useQuery( + undefined, + { + refetchInterval: 1000, + placeholderData: keepPreviousData, + }, + ); + + if (!serverStats) { + return ; + } + + return ( +
+
+ {t("admin.background_jobs.background_jobs")} +
+
+ + + {t("admin.background_jobs.job")} + {t("admin.background_jobs.queued")} + {t("admin.background_jobs.pending")} + {t("admin.background_jobs.failed")} + + + + + {t("admin.background_jobs.crawler_jobs")} + + {serverStats.crawlStats.queued} + {serverStats.crawlStats.pending} + {serverStats.crawlStats.failed} + + + {t("admin.background_jobs.indexing_jobs")} + {serverStats.indexingStats.queued} + - + - + + + {t("admin.background_jobs.inference_jobs")} + {serverStats.inferenceStats.queued} + {serverStats.inferenceStats.pending} + {serverStats.inferenceStats.failed} + + + + {t("admin.background_jobs.tidy_assets_jobs")} + + {serverStats.tidyAssetsStats.queued} + - + - + + + {t("admin.background_jobs.video_jobs")} + {serverStats.videoStats.queued} + - + - + + + {t("admin.background_jobs.webhook_jobs")} + {serverStats.webhookStats.queued} + - + - + + + + {t("admin.background_jobs.asset_preprocessing_jobs")} + + + {serverStats.assetPreprocessingStats.queued} + + - + - + + + {t("admin.background_jobs.feed_jobs")} + {serverStats.feedStats.queued} + - + - + + +
+
+ +
+ ); +} -- cgit v1.2.3-70-g09d2