@@ -4,26 +4,17 @@ const seriesQueue = require('./seriesQueue');
44const ArgumentError = require ( '../../errors' ) . ArgumentError ;
55const NotFoundError = require ( '../../errors' ) . NotFoundError ;
66const ValidationError = require ( '../../errors' ) . ValidationError ;
7- const logger = require ( '../../logger' ) ;
87
98const getDataForCollection = function ( storageContext , collectionName ) {
10- logger . info ( '[getDataForCollection] Reading data for collection:' , collectionName ) ;
119 return storageContext . read ( )
1210 . then ( function ( data ) {
13- logger . info ( '[getDataForCollection] Data read successfully, keys:' , Object . keys ( data || { } ) ) ;
1411 data [ collectionName ] = data [ collectionName ] || [ ] ;
15- logger . info ( '[getDataForCollection] Collection' , collectionName , 'has' , data [ collectionName ] . length , 'items' ) ;
1612 return data ;
17- } )
18- . catch ( function ( err ) {
19- logger . info ( '[getDataForCollection] Error reading data:' , err . message || err ) ;
20- throw err ;
2113 } ) ;
2214} ;
2315
2416// Simple promise retry implementation
2517const promiseRetry = function ( fn , options ) {
26- logger . info ( '[promiseRetry] Starting with options:' , JSON . stringify ( options ) ) ;
2718 let attempt = 0 ;
2819 const maxRetries = options . retries || 10 ;
2920 const factor = options . factor || 2 ;
@@ -32,26 +23,20 @@ const promiseRetry = function(fn, options) {
3223
3324 const retry = function ( err ) {
3425 attempt ++ ;
35- logger . info ( '[promiseRetry] Retry attempt' , attempt , 'of' , maxRetries ) ;
36- logger . info ( '[promiseRetry] Retry error:' , err . message || err ) ;
3726 if ( attempt > maxRetries ) {
38- logger . info ( '[promiseRetry] Max retries exceeded, rejecting' ) ;
3927 return Promise . reject ( err ) ;
4028 }
4129
4230 // Calculate timeout with exponential backoff
4331 const timeout = Math . min ( minTimeout * Math . pow ( factor , attempt - 1 ) , maxTimeout ) ;
44- logger . info ( '[promiseRetry] Waiting' , timeout , 'ms before retry' ) ;
4532
4633 return new Promise ( function ( resolve ) {
4734 setTimeout ( resolve , timeout ) ;
4835 } ) . then ( function ( ) {
49- logger . info ( '[promiseRetry] Retrying function after timeout' ) ;
5036 return fn ( retry ) ;
5137 } ) ;
5238 } ;
5339
54- logger . info ( '[promiseRetry] Executing function (attempt 0)' ) ;
5540 return fn ( retry ) ;
5641} ;
5742
@@ -65,27 +50,16 @@ const withRetry = function(storageContext, action) {
6550 } ;
6651
6752 return function ( ) {
68- logger . info ( '[withRetry] Starting action with retry wrapper' ) ;
6953 return promiseRetry ( function ( retry ) {
70- logger . info ( '[withRetry] Executing action' ) ;
7154 return action ( )
72- . then ( function ( result ) {
73- logger . info ( '[withRetry] Action succeeded' ) ;
74- return result ;
75- } )
7655 . catch ( function ( err ) {
77- logger . info ( '[withRetry] Action failed:' , err . message || err ) ;
7856 const writeRetryCondition =
7957 storageContext . writeRetryCondition ||
8058 function ( ) { return false ; } ;
81- const shouldRetry = writeRetryCondition ( err ) ;
82- logger . info ( '[withRetry] Should retry:' , shouldRetry ) ;
83- if ( shouldRetry ) {
84- logger . info ( '[withRetry] Retrying due to write conflict' ) ;
59+ if ( writeRetryCondition ( err ) ) {
8560 return retry ( err ) ;
8661 }
8762
88- logger . info ( '[withRetry] Not retrying, throwing error' ) ;
8963 throw err ;
9064 } ) ;
9165 } , retryOptions ) ;
0 commit comments