tracks lexicons and how many times they appeared on the jetstream
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: retry jetstream connection if it fails

dusk 19a17895 985548e6

+24 -3
+2 -2
src/hooks.server.ts
··· 1 - import { startTracking, writeEvents } from "$lib/jetstream.js"; 1 + import { track, writeEvents } from "$lib/jetstream.js"; 2 2 3 3 // Start tracking when the server starts 4 - startTracking().catch(console.error); 4 + track().catch(console.error); 5 5 process.on("SIGINT", writeEvents); 6 6 process.on("SIGTERM", writeEvents); 7 7 process.on("SIGQUIT", writeEvents);
+22 -1
src/lib/jetstream.ts
··· 13 13 eventsToCommit = []; 14 14 }; 15 15 16 - export const startTracking = async () => { 16 + const startTracking = async () => { 17 17 subscription = new JetstreamSubscription({ 18 18 url: "wss://jetstream2.us-east.bsky.network", 19 19 validateEvents: false, // trust the jetstream :3 ··· 40 40 41 41 writeEvents(); 42 42 }; 43 + 44 + export const track = async () => { 45 + let retryCount = 0; 46 + const baseDelay = 1000; // 1 second 47 + const maxDelay = 60000; // 60 seconds 48 + 49 + while (true) { 50 + try { 51 + await startTracking(); 52 + retryCount = 0; // Reset on success 53 + } catch (e) { 54 + console.log(`tracking failed: ${e}`); 55 + 56 + const delay = Math.min(baseDelay * Math.pow(2, retryCount), maxDelay); 57 + console.log(`retrying in ${delay}ms (attempt ${retryCount + 1})`); 58 + 59 + await new Promise((resolve) => setTimeout(resolve, delay)); 60 + retryCount++; 61 + } 62 + } 63 + };