@@ -8,12 +8,13 @@ import { updateEnrichedRepos } from './updateEnrichedRepos'
88
99const log = getServiceChildLogger ( 'github-repos-enricher' )
1010
11+ const MAX_RETRIES = 3
12+
1113async function fetchWithRetries (
1214 url : string ,
1315 token : string ,
14- maxRetries : number ,
1516) : Promise < LightRepoResult | null > {
16- for ( let attempt = 0 ; attempt <= maxRetries ; attempt ++ ) {
17+ for ( let attempt = 0 ; attempt <= MAX_RETRIES ; attempt ++ ) {
1718 try {
1819 return await fetchLightRepo ( url , token )
1920 } catch ( err ) {
@@ -26,12 +27,12 @@ async function fetchWithRetries(
2627
2728 if ( err . kind === 'RATE_LIMIT' ) throw err
2829
29- if ( attempt < maxRetries ) {
30+ if ( attempt < MAX_RETRIES ) {
3031 const backoffMs = 1000 * 2 ** attempt
3132 log . warn ( { url, attempt, backoffMs } , `Transient error, retrying: ${ err . message } ` )
3233 await new Promise ( ( r ) => setTimeout ( r , backoffMs ) )
3334 } else {
34- log . error ( { url } , `Gave up after ${ maxRetries } retries: ${ err . message } ` )
35+ log . error ( { url } , `Gave up after ${ MAX_RETRIES } retries: ${ err . message } ` )
3536 return null
3637 }
3738 }
@@ -42,7 +43,7 @@ async function fetchWithRetries(
4243async function fetchPage (
4344 qx : QueryExecutor ,
4445 cursor : string | null ,
45- pageSize : number ,
46+ batchSize : number ,
4647 updateIntervalHours : number ,
4748) : Promise < { rows : Array < { id : string ; url : string } > ; urls : string [ ] } > {
4849 const rows = await qx . select (
@@ -53,9 +54,9 @@ async function fetchPage(
5354 AND (last_synced_at IS NULL OR last_synced_at < NOW() - INTERVAL '$(updateIntervalHours) hours')
5455 AND ($(cursor) IS NULL OR id > $(cursor))
5556 ORDER BY id
56- LIMIT $(pageSize )
57+ LIMIT $(batchSize )
5758 ` ,
58- { cursor, pageSize , updateIntervalHours } ,
59+ { cursor, batchSize , updateIntervalHours } ,
5960 )
6061 return {
6162 rows,
@@ -103,7 +104,7 @@ async function processPage(
103104 const url = validUrls [ idx ]
104105
105106 try {
106- const result = await fetchWithRetries ( url , token , config . maxRetries )
107+ const result = await fetchWithRetries ( url , token )
107108 if ( result ) {
108109 buffer . push ( result )
109110 if ( buffer . length >= config . batchSize ) {
@@ -161,7 +162,7 @@ export async function runEnrichmentLoop(
161162 while ( ! isShuttingDown ( ) ) {
162163 pageNum ++
163164
164- const { rows, urls } = await fetchPage ( qx , cursor , config . pageSize , config . updateIntervalHours )
165+ const { rows, urls } = await fetchPage ( qx , cursor , config . batchSize , config . updateIntervalHours )
165166
166167 if ( urls . length === 0 ) {
167168 log . info ( 'No more repos to process, sleeping' )
0 commit comments