From 6ea5dd194e7be62c1a51566f31808be076d3b139 Mon Sep 17 00:00:00 2001
From: Mohamed Bassem <me@mbassem.com>
Date: Sun, 26 Oct 2025 09:58:51 +0000
Subject: refactor: generalize tidy assets queue into admin maintenance (#2059)

* refactor: generalize admin maintenance queue

* more fixes
---
 apps/web/components/admin/BackgroundJobs.tsx | 53 +++++++++++++++++-----------
 1 file changed, 32 insertions(+), 21 deletions(-)

(limited to 'apps/web/components/admin/BackgroundJobs.tsx')

diff --git a/apps/web/components/admin/BackgroundJobs.tsx b/apps/web/components/admin/BackgroundJobs.tsx
index 569fd67a..5920b1ab 100644
--- a/apps/web/components/admin/BackgroundJobs.tsx
+++ b/apps/web/components/admin/BackgroundJobs.tsx
@@ -320,20 +320,22 @@ function useJobActions() {
     },
   });
 
-  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,
-        });
-      },
-    });
+  const {
+    mutateAsync: runAdminMaintenanceTask,
+    isPending: isAdminMaintenancePending,
+  } = api.admin.runAdminMaintenanceTask.useMutation({
+    onSuccess: () => {
+      toast({
+        description: "Admin maintenance request has been enqueued!",
+      });
+    },
+    onError: (e) => {
+      toast({
+        variant: "destructive",
+        description: e.message,
+      });
+    },
+  });
 
   return {
     crawlActions: [
@@ -409,11 +411,18 @@ function useJobActions() {
         loading: isReprocessingPending,
       },
     ],
-    tidyAssetsActions: [
+    adminMaintenanceActions: [
       {
         label: t("admin.background_jobs.actions.clean_assets"),
-        onClick: () => tidyAssets(),
-        loading: isTidyAssetsPending,
+        onClick: () =>
+          runAdminMaintenanceTask({
+            type: "tidy_assets",
+            args: {
+              cleanDanglingAssets: true,
+              syncAssetMetadata: true,
+            },
+          }),
+        loading: isAdminMaintenancePending,
       },
     ],
   };
@@ -480,11 +489,13 @@ export default function BackgroundJobs() {
       actions: actions.assetPreprocessingActions,
     },
     {
-      title: t("admin.background_jobs.jobs.tidy_assets.title"),
+      title: t("admin.background_jobs.jobs.admin_maintenance.title"),
       icon: Database,
-      stats: { queued: serverStats.tidyAssetsStats.queued },
-      description: t("admin.background_jobs.jobs.tidy_assets.description"),
-      actions: actions.tidyAssetsActions,
+      stats: { queued: serverStats.adminMaintenanceStats.queued },
+      description: t(
+        "admin.background_jobs.jobs.admin_maintenance.description",
+      ),
+      actions: actions.adminMaintenanceActions,
     },
     {
       title: t("admin.background_jobs.jobs.video.title"),
-- 
cgit v1.2.3-70-g09d2

