Example #1
0
        public static Task FlushAsync(this IBucketManager bucketManager, string bucketName, Action <FlushBucketOptions> configureOptions)
        {
            var options = new FlushBucketOptions();

            configureOptions(options);

            return(bucketManager.Flush(bucketName, options));
        }
Example #2
0
        public async Task Flush(string bucketName, FlushBucketOptions options)
        {
            // get uri and amend path to flush endpoint
            var builder = new UriBuilder(GetUri(bucketName));

            builder.Path = Path.Combine(builder.Path, "controller/doFlush");
            var uri = builder.Uri;

            Logger.LogInformation($"Attempting to flush bucket with name {bucketName} - {uri}");

            try
            {
                // try get bucket, throws BucketNotFoundException if it doesn't exist
                var settings = await GetAsync(bucketName, GetBucketOptions.Default);

                if (!settings.FlushEnabled)
                {
                    // does not support flush
                    throw new BucketIsNotFlushableException(bucketName);
                }

                // do flush
                var result = await _client.PostAsync(uri, null, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
            }
            catch (BucketNotFoundException)
            {
                Logger.LogError($"Unable to flush bucket with name {bucketName} because it does not exist");
                throw;
            }
            catch (BucketIsNotFlushableException)
            {
                Logger.LogError($"Failed to flush bucket with name {bucketName} because it is not flushable");
                throw;
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to flush bucket with name {bucketName}");
                throw;
            }
        }