Sfoglia il codice sorgente

Add 200ms delay before refetching status after start/stop

- Backend may need time to update state before status endpoint reflects changes
- Wait 200ms before refetching to ensure backend has updated
- Move toast after refetch so user sees updated status before success message
- Applies to both FileWatcherCard and TaskProcessingCard
Timothy Pomeroy 3 settimane fa
parent
commit
bbb8241194

+ 6 - 4
apps/web/src/app/components/FileWatcherCard.tsx

@@ -26,9 +26,10 @@ export default function FileWatcherCard() {
   const startWatcherMutation = useMutation({
     mutationFn: () => post("/watcher/start"),
     onSuccess: async () => {
-      toast.success("File watcher started");
-      // Force immediate refetch
+      // Small delay to let backend update state
+      await new Promise((resolve) => setTimeout(resolve, 200));
       await refetchWatcherStatus();
+      toast.success("File watcher started");
     },
     onError: () => {
       toast.error("Failed to start file watcher");
@@ -38,9 +39,10 @@ export default function FileWatcherCard() {
   const stopWatcherMutation = useMutation({
     mutationFn: () => post("/watcher/stop"),
     onSuccess: async () => {
-      toast.success("File watcher stopped");
-      // Force immediate refetch
+      // Small delay to let backend update state
+      await new Promise((resolve) => setTimeout(resolve, 200));
       await refetchWatcherStatus();
+      toast.success("File watcher stopped");
     },
     onError: () => {
       toast.error("Failed to stop file watcher");

+ 6 - 2
apps/web/src/app/components/TaskProcessingCard.tsx

@@ -39,9 +39,11 @@ export default function TaskProcessingCard() {
   const startTaskProcessingMutation = useMutation({
     mutationFn: () => post("/tasks/start-processing"),
     onSuccess: async () => {
-      toast.success("Task processing started");
+      // Small delay to let backend update state
+      await new Promise((resolve) => setTimeout(resolve, 200));
       await refetchTaskProcessingStatus();
       queryClient.invalidateQueries({ queryKey: ["tasks", "queue", "status"] });
+      toast.success("Task processing started");
     },
     onError: () => {
       toast.error("Failed to start task processing");
@@ -51,9 +53,11 @@ export default function TaskProcessingCard() {
   const stopTaskProcessingMutation = useMutation({
     mutationFn: () => post("/tasks/stop-processing"),
     onSuccess: async () => {
-      toast.success("Task processing stopped");
+      // Small delay to let backend update state
+      await new Promise((resolve) => setTimeout(resolve, 200));
       await refetchTaskProcessingStatus();
       queryClient.invalidateQueries({ queryKey: ["tasks", "queue", "status"] });
+      toast.success("Task processing stopped");
     },
     onError: () => {
       toast.error("Failed to stop task processing");