@@ -29,14 +29,17 @@ static async Task<string> Handler(LinkReference linkReference, ILambdaContext co
2929 const int maxRetries = 3 ;
3030 var retryCount = 0 ;
3131
32- while ( retryCount < maxRetries )
32+ while ( true )
3333 {
3434 var sw = Stopwatch . StartNew ( ) ;
3535
3636 IAmazonS3 s3Client = new AmazonS3Client ( ) ;
3737 var linkIndex = await CreateLinkIndex ( s3Client ) ;
3838 if ( linkIndex == null )
39+ {
40+ context . Logger . LogLine ( $ "Error encountered on server. getting list of objects.") ;
3941 return $ "Error encountered on server. getting list of objects.";
42+ }
4043
4144 var json = LinkIndex . Serialize ( linkIndex ) ;
4245
@@ -63,22 +66,22 @@ static async Task<string> Handler(LinkReference linkReference, ILambdaContext co
6366 try
6467 {
6568 var putObjectResponse = await s3Client . PutObjectAsync ( putObjectRequest ) ;
69+ context . Logger . LogLine ( $ "Created link object with ETag { putObjectResponse . ETag } ") ;
70+ context . Logger . LogLine ( $ "Link Index: { json } ") ;
6671 return $ "Finished in { sw } ";
6772 }
6873 catch ( AmazonS3Exception ex ) when ( ex . ErrorCode == "PreconditionFailed" )
6974 {
7075 retryCount ++ ;
7176 if ( retryCount >= maxRetries )
7277 {
78+ context . Logger . LogLine ( $ "Error encountered on server. getting object { getObjectRequest . Key } .") ;
7379 return $ "Error: Failed to update after { maxRetries } attempts. Someone else modified the object since we read it. { ex . Message } ";
7480 }
7581 // Wait a short time before retrying
7682 await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
77- continue ;
7883 }
7984 }
80-
81- return "Unexpected error: Retry loop completed without success" ;
8285}
8386
8487static async Task < LinkIndex ? > CreateLinkIndex ( IAmazonS3 s3Client )
0 commit comments