public async Task BuildDeferredIndexesAsync(string bucketName, BuildDeferredQueryIndexOptions options = null)
        {
            options = options ?? BuildDeferredQueryIndexOptions.Default;
            Logger.LogInformation($"Attempting to build deferred query indexes on bucket {bucketName}");
            try
            {
                var indexes = await this.GetAllIndexesAsync(bucketName,
                                                            queryOptions => queryOptions.WithCancellationToken(options.CancellationToken)
                                                            );

                var tasks = new List <Task>();
                foreach (var index in indexes.Where(i => i.State == "pending" || i.State == "deferred"))
                {
                    var statement = $"BUILD INDEX ON {bucketName}({index.Name}) USING GSI;";
                    tasks.Add(_queryClient.QueryAsync <dynamic>(statement,
                                                                queryOptions => queryOptions.WithCancellationToken(options.CancellationToken)
                                                                ));
                }

                await Task.WhenAll(tasks);
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Error trying to build deferred query indexes on {bucketName}");
                throw;
            }
        }
        public static Task BuildDeferredIndexesAsync(this IQueryIndexManager queryIndexManager, string bucketName, Action <BuildDeferredQueryIndexOptions> configureOptions)
        {
            var options = new BuildDeferredQueryIndexOptions();

            configureOptions(options);

            return(queryIndexManager.BuildDeferredIndexesAsync(bucketName, options));
        }
Ejemplo n.º 3
0
 public static string CreateDeferredIndexStatement(string bucketName, string indexName, BuildDeferredQueryIndexOptions options)
 {
     if(options.ScopeNameValue == null)
     {
         return $"BUILD INDEX ON {bucketName.EscapeIfRequired()}({indexName}) USING GSI;";
     }
     return $"BUILD INDEX ON {bucketName.EscapeIfRequired()}.{options.ScopeNameValue.EscapeIfRequired()}.{options.CollectionNameValue.EscapeIfRequired()}({indexName}) USING GSI;";
 }