public static Task WatchIndexesAsync(this IQueryIndexManager queryIndexManager, string bucketName, IEnumerable <string> indexNames, Action <WatchQueryIndexOptions> configureOptions) { var options = new WatchQueryIndexOptions(); configureOptions(options); return(queryIndexManager.WatchIndexesAsync(bucketName, indexNames, options)); }
public async Task WatchIndexesAsync(string bucketName, IEnumerable <string> indexNames, WatchQueryIndexOptions options = null) { options = options ?? WatchQueryIndexOptions.Default; var indexesToWatch = string.Join(", ", indexNames.ToList()); Logger.LogInformation($"Attempting to watch pending indexes ({indexesToWatch}) for bucket {bucketName}"); try { while (!options.CancellationToken.IsCancellationRequested) { var indexes = await this.GetAllIndexesAsync(bucketName, queryOptions => queryOptions.WithCancellationToken(options.CancellationToken) ); var pendingIndexes = indexes.Where(index => index.State != "online") .Select(index => index.Name) .Intersect(indexNames); if (!pendingIndexes.Any()) { break; } Logger.LogInformation($"Still waiting for indexes to complete building ({indexesToWatch})"); await Task.Delay(WatchIndexSleepDuration); } } catch (TaskCanceledException) { // application cancelled watch task } catch (Exception exception) { Logger.LogError(exception, $"Error trying to watch pending indexes ({indexesToWatch}) for bucket {bucketName}"); throw; } }