tangled
alpha
login
or
join now
dunkirk.sh
/
pstream-ng
1
fork
atom
pstream is dead; long live pstream
taciturnaxolotl.github.io/pstream-ng/
1
fork
atom
overview
issues
pulls
pipelines
add bookmark sync retry to prevent failures
Pas
3 weeks ago
1bb1e2f9
387982d2
+17
-4
1 changed file
expand all
collapse all
unified
split
src
stores
trakt
TraktBookmarkSyncer.tsx
+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
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
46
+
const [retryTrigger, setRetryTrigger] = useState(0);
45
47
46
46
-
// Sync from Local to Trakt
48
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
52
+
let retryTimeoutId: ReturnType<typeof setTimeout> | undefined;
53
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
55
-
removeTraktUpdateItem(item.id);
56
56
-
57
59
try {
58
60
const contentData: TraktContentData = {
59
61
title: item.title ?? "",
···
112
114
// }
113
115
// }
114
116
}
117
117
+
118
118
+
removeTraktUpdateItem(item.id);
115
119
} catch (error) {
116
120
console.error("Failed to sync bookmark to Trakt", error);
121
121
+
if (!retryTimeoutId) {
122
122
+
retryTimeoutId = setTimeout(
123
123
+
() => setRetryTrigger((n) => n + 1),
124
124
+
QUEUE_RETRY_DELAY_MS,
125
125
+
);
126
126
+
}
117
127
}
118
128
}
119
129
};
120
130
121
131
processQueue();
122
122
-
}, [accessToken, traktUpdateQueue, removeTraktUpdateItem]);
132
132
+
return () => {
133
133
+
if (retryTimeoutId) clearTimeout(retryTimeoutId);
134
134
+
};
135
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 () => {