retryTidbDataEndpointUntilDeployed function
Retries a newly deployed endpoint while TiDB propagates the deployment.
Implementation
Future<Map<String, dynamic>> retryTidbDataEndpointUntilDeployed(
Future<Map<String, dynamic>> Function() call, {
Duration pollInterval = const Duration(seconds: 2),
int maxAttempts = 10,
}) async {
for (var attempt = 0; attempt < maxAttempts; attempt++) {
try {
return await call();
} on HttpException catch (exception) {
if (attempt == maxAttempts - 1 ||
!exception.message.contains("deployed endpoint not found")) {
rethrow;
}
await Future<void>.delayed(pollInterval);
}
}
throw StateError("TiDB Data Service endpoint retry was exhausted.");
}