@@ -7,7 +7,7 @@ const CONCURRENCY_LIMIT = 50; // Number of concurrent fetches allowed
77const limitFetch = pLimit ( CONCURRENCY_LIMIT ) ;
88
99export async function backfillGuards ( ) {
10- console . info ( '[INFO][WORKER][BIZ_FLOW] Starting guards backfill process ...' ) ;
10+ console . info ( '[INFO][WORKER][BIZ_FLOW] Starting guards backfill ...' ) ;
1111
1212 const deleteGuardsQuery = `
1313 DELETE FROM "Guards";
@@ -20,7 +20,7 @@ export async function backfillGuards() {
2020 let currentId = 0 ;
2121
2222 while ( true ) {
23- console . info ( `[INFO][DB][METRIC] Processing guards batch: ${ offset } -${ offset + limit } ` ) ;
23+ console . info ( `[INFO][DB][METRIC] Processing guards batch: ${ currentId } -${ currentId + limit } ` ) ;
2424 const res = await rootPgPool . query (
2525 `
2626 SELECT b.id, b.account, b."chainId", b.module
@@ -34,7 +34,7 @@ export async function backfillGuards() {
3434
3535 const rows = res . rows ;
3636 if ( rows . length === 0 ) {
37- console . info ( '[INFO][DB][DATA_MISSING] No more balance rows to process. Backfill complete. ' ) ;
37+ console . info ( '[INFO][DB][DATA_MISSING] No more balance rows to process.' ) ;
3838 break ;
3939 }
4040
@@ -59,21 +59,18 @@ export async function backfillGuards() {
5959 } ) ;
6060
6161 await tx . commit ( ) ;
62- console . info ( `[INFO][DB][BIZ_FLOW] Batch at offset ${ offset } processed successfully.` ) ;
63- offset += limit ;
62+ console . info ( `[INFO][DB][BIZ_FLOW] Row at ${ currentId } id processed successfully.` ) ;
63+ currentId = rows [ rows . length - 1 ] . id ;
6464 } catch ( batchError ) {
65- console . error (
66- `[ERROR][DB][DATA_CORRUPT] Failed to process guards batch at offset ${ offset } :` ,
67- batchError ,
68- ) ;
65+ console . error ( `Error processing at id ${ currentId } :` , batchError ) ;
6966 try {
7067 await tx . rollback ( ) ;
71- console . info ( `[INFO][DB][BIZ_FLOW] Transaction for batch at offset ${ offset } rolled back.` ) ;
68+ console . info ( `[INFO][DB][BIZ_FLOW] Transaction for id at ${ currentId } rolled back.` ) ;
7269 } catch ( rollbackError ) {
73- console . error ( '[ERROR][DB][SYNC_CONFLICT] Transaction rollback failed :' , rollbackError ) ;
70+ console . error ( 'Error during rollback:' , rollbackError ) ;
7471 }
7572 break ;
7673 }
7774 }
78- console . info ( '[INFO][WORKER][BIZ_FLOW] Guards backfill completed successfully.' ) ;
75+ console . info ( '[INFO][WORKER][BIZ_FLOW] Guards backfilled successfully.' ) ;
7976}
0 commit comments