@@ -25,19 +25,27 @@ public class TableStorageScaleMetricsRepository : IScaleMetricsRepository
25
25
private const string MonitorIdPropertyName = "MonitorId" ;
26
26
private const string SampleTimestampPropertyName = "SampleTimestamp" ;
27
27
private const int MetricsPurgeDelaySeconds = 30 ;
28
+ private const int DefaultTableCreationRetries = 3 ;
28
29
29
30
private readonly IConfiguration _configuration ;
30
31
private readonly IHostIdProvider _hostIdProvider ;
31
32
private readonly ScaleOptions _scaleOptions ;
32
33
private readonly ILogger _logger ;
34
+ private readonly int _tableCreationRetries ;
33
35
private CloudTableClient _tableClient ;
34
36
35
37
public TableStorageScaleMetricsRepository ( IConfiguration configuration , IHostIdProvider hostIdProvider , IOptions < ScaleOptions > scaleOptions , ILoggerFactory loggerFactory )
38
+ : this ( configuration , hostIdProvider , scaleOptions , loggerFactory , DefaultTableCreationRetries )
39
+ {
40
+ }
41
+
42
+ internal TableStorageScaleMetricsRepository ( IConfiguration configuration , IHostIdProvider hostIdProvider , IOptions < ScaleOptions > scaleOptions , ILoggerFactory loggerFactory , int tableCreationRetries )
36
43
{
37
44
_configuration = configuration ;
38
45
_hostIdProvider = hostIdProvider ;
39
46
_scaleOptions = scaleOptions . Value ;
40
47
_logger = loggerFactory . CreateLogger < TableStorageScaleMetricsRepository > ( ) ;
48
+ _tableCreationRetries = tableCreationRetries ;
41
49
}
42
50
43
51
internal CloudTableClient TableClient
@@ -199,7 +207,7 @@ internal async Task ExecuteBatchSafeAsync(TableBatchOperation batch, DateTime? n
199
207
}
200
208
}
201
209
202
- internal async Task CreateIfNotExistsAsync ( CloudTable table , int retryCount = 3 , int retryDelayMS = 1000 )
210
+ internal async Task CreateIfNotExistsAsync ( CloudTable table , int retryDelayMS = 1000 )
203
211
{
204
212
int attempt = 0 ;
205
213
do
@@ -222,7 +230,8 @@ internal async Task CreateIfNotExistsAsync(CloudTable table, int retryCount = 3,
222
230
// though these should only happen in tests not production, because we only ever
223
231
// delete OLD tables and we'll never be attempting to recreate a table we just
224
232
// deleted outside of tests.
225
- if ( e . RequestInformation . HttpStatusCode == ( int ) HttpStatusCode . Conflict )
233
+ if ( e . RequestInformation . HttpStatusCode == ( int ) HttpStatusCode . Conflict &&
234
+ attempt < _tableCreationRetries )
226
235
{
227
236
// wait a bit and try again
228
237
await Task . Delay ( retryDelayMS ) ;
@@ -233,7 +242,7 @@ internal async Task CreateIfNotExistsAsync(CloudTable table, int retryCount = 3,
233
242
234
243
return ;
235
244
}
236
- while ( attempt ++ < retryCount ) ;
245
+ while ( attempt ++ < _tableCreationRetries ) ;
237
246
}
238
247
239
248
internal async Task AccumulateMetricsBatchAsync ( TableBatchOperation batch , IScaleMonitor monitor , IEnumerable < ScaleMetrics > metrics , DateTime ? now = null )
0 commit comments