pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/

add bookmark sync retry to prevent failures

Pas 1bb1e2f9 387982d2

+17 -4
+17 -4
src/stores/trakt/TraktBookmarkSyncer.tsx
··· 9 9 10 10 const TRAKT_SYNC_INTERVAL_MS = 5 * 60 * 1000; // 5 min 11 11 const INITIAL_SYNC_DELAY_MS = 2000; // Re-sync after backend restore 12 + const QUEUE_RETRY_DELAY_MS = 5000; // Retry failed queue items after 5s 12 13 13 14 // Collections/groups sync disabled for now - bookmarks only sync to watchlist 14 15 // import { modifyBookmarks } from "@/utils/bookmarkModifications"; ··· 42 43 const { accessToken } = useTraktAuthStore(); 43 44 const isSyncingRef = useRef(false); 44 45 const [hydrated, setHydrated] = useState(false); 46 + const [retryTrigger, setRetryTrigger] = useState(0); 45 47 46 - // Sync from Local to Trakt 48 + // Sync from Local to Trakt (only remove from queue after API success; retry on failure) 47 49 useEffect(() => { 48 50 if (!accessToken) return; 49 51 52 + let retryTimeoutId: ReturnType<typeof setTimeout> | undefined; 53 + 50 54 const processQueue = async () => { 51 55 const queue = [...traktUpdateQueue]; 52 56 if (queue.length === 0) return; 53 57 54 58 for (const item of queue) { 55 - removeTraktUpdateItem(item.id); 56 - 57 59 try { 58 60 const contentData: TraktContentData = { 59 61 title: item.title ?? "", ··· 112 114 // } 113 115 // } 114 116 } 117 + 118 + removeTraktUpdateItem(item.id); 115 119 } catch (error) { 116 120 console.error("Failed to sync bookmark to Trakt", error); 121 + if (!retryTimeoutId) { 122 + retryTimeoutId = setTimeout( 123 + () => setRetryTrigger((n) => n + 1), 124 + QUEUE_RETRY_DELAY_MS, 125 + ); 126 + } 117 127 } 118 128 } 119 129 }; 120 130 121 131 processQueue(); 122 - }, [accessToken, traktUpdateQueue, removeTraktUpdateItem]); 132 + return () => { 133 + if (retryTimeoutId) clearTimeout(retryTimeoutId); 134 + }; 135 + }, [accessToken, traktUpdateQueue, removeTraktUpdateItem, retryTrigger]); 123 136 124 137 // Push local bookmarks to Trakt watchlist (TODO implement collections/groups sync) 125 138 const syncBookmarksToTrakt = useCallback(async () => {