retryTidbDataEndpointUntilDeployed function

Future<Map<String, dynamic>> retryTidbDataEndpointUntilDeployed(
  1. Future<Map<String, dynamic>> call(), {
  2. Duration pollInterval = const Duration(seconds: 2),
  3. int maxAttempts = 10,
})

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.");
}