this repo has no description
0
fork

Configure Feed

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

Fix cursor handling

alice a322759a 1dc04a39

+17 -10
+1
.env.example
··· 5 5 PORT=4002 6 6 METRICS_PORT=4102 7 7 FIREHOSE_URL=wss://jetstream.atproto.tools/subscribe 8 + CURSOR_UPDATE_INTERVAL=10000
+1 -1
package.json
··· 21 21 }, 22 22 "dependencies": { 23 23 "@atproto/api": "^0.13.8", 24 - "@skyware/jetstream": "^0.1.5", 24 + "@skyware/jetstream": "^0.1.6", 25 25 "@skyware/labeler": "^0.1.7", 26 26 "dotenv": "^16.4.5", 27 27 "express": "^4.21.0",
+2
src/config.ts
··· 8 8 export const WANTED_COLLECTION = 'app.bsky.feed.like'; 9 9 export const BSKY_IDENTIFIER = process.env.BSKY_IDENTIFIER ?? ''; 10 10 export const BSKY_PASSWORD = process.env.BSKY_PASSWORD ?? ''; 11 + export const CURSOR_UPDATE_INTERVAL = 12 + process.env.CURSOR_UPDATE_INTERVAL ? Number(process.env.CURSOR_UPDATE_INTERVAL) : 10000;
+13 -9
src/main.ts
··· 1 1 import { CommitCreateEvent, Jetstream } from '@skyware/jetstream'; 2 2 import fs from 'node:fs'; 3 3 4 - import { DID, FIREHOSE_URL, METRICS_PORT, PORT, WANTED_COLLECTION } from './config.js'; 4 + import { CURSOR_UPDATE_INTERVAL, DID, FIREHOSE_URL, METRICS_PORT, PORT, WANTED_COLLECTION } from './config.js'; 5 5 import { label, labelerServer } from './label.js'; 6 6 import logger from './logger.js'; 7 7 import { startMetricsServer } from './metrics.js'; 8 8 9 9 let cursor = 0; 10 10 let cursorUpdateInterval: NodeJS.Timeout; 11 - let cursorFile: string; 12 11 13 12 try { 14 - cursorFile = fs.readFileSync('cursor.txt', 'utf8'); 13 + logger.info('Trying to read cursor from cursor.txt...'); 14 + cursor = Number(fs.readFileSync('cursor.txt', 'utf8')); 15 + logger.info(`Cursor found: ${cursor} (${new Date(cursor / 1000).toISOString()})`); 15 16 } catch (error) { 16 17 if (error instanceof Error && 'code' in error && error.code === 'ENOENT') { 17 - cursorFile = (BigInt(Date.now()) * 1000n).toString(); 18 - fs.writeFileSync('cursor.txt', cursorFile, 'utf8'); 18 + logger.info( 19 + `Cursor not found in cursor.txt, setting cursor to: ${cursor} (${new Date(cursor / 1000).toISOString()})`, 20 + ); 21 + fs.writeFileSync('cursor.txt', cursor.toString(), 'utf8'); 19 22 } else { 20 23 logger.error(error); 21 24 process.exit(1); ··· 25 28 const jetstream = new Jetstream({ 26 29 wantedCollections: [WANTED_COLLECTION], 27 30 endpoint: FIREHOSE_URL, 28 - cursor: cursor.toString(), 31 + cursor: cursor, 29 32 }); 30 33 31 34 jetstream.on('open', () => { 32 - logger.info('Connected to Jetstream'); 35 + logger.info(`Connected to Jetstream at ${FIREHOSE_URL}`); 33 36 cursorUpdateInterval = setInterval(() => { 34 - logger.info(`Cursor updated at ${new Date().toISOString()} to: ${cursor}`); 37 + logger.info(`Cursor updated to: ${cursor} (${new Date(cursor / 1000).toISOString()})`); 35 38 fs.writeFile('cursor.txt', cursor.toString(), (err) => { 36 39 if (err) logger.error(err); 37 40 }); 38 - }, 10000); 41 + }, CURSOR_UPDATE_INTERVAL); 39 42 }); 40 43 41 44 jetstream.on('close', () => { 45 + clearInterval(cursorUpdateInterval); 42 46 logger.info('Jetstream connection closed.'); 43 47 }); 44 48