/// <inheritdoc /> public async Task <InsertEventsResult> InsertAsync( InsertEventsQuery query, TimeSpan timeout, CancellationToken cancellationToken = default) { try { using (var disposable = writersPool.Acquire(out var buffer)) { buffer.Reset(); var content = new ValueDisposable <Content>(CreateContent(query, buffer), disposable); var response = await sender .SendAsync(query.Stream, settings.ApiKeyProvider(), content, timeout, cancellationToken) .ConfigureAwait(false); return(response); } } catch (Exception error) { log.Warn(error); return(new InsertEventsResult(HerculesStatus.UnknownError, error.Message)); } }
private void SetupResponses(params HerculesStatus[] statuses) { if (statuses.Length == 0) { return; } requestSender.SendAsync( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <ValueDisposable <Content> >(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>()) .Returns(new InsertEventsResult(statuses.First()), statuses.Skip(1).Select(status => new InsertEventsResult(status)).ToArray()); }
private async Task <HerculesStatus> SendBatchAsync([NotNull] IReadOnlyList <BufferSnapshot> batch, TimeSpan timeout, CancellationToken cancellationToken) { var watch = Stopwatch.StartNew(); using (var content = contentFactory.CreateContent(batch, out var recordsCount, out var recordsSize)) { var response = await gateRequestSender .SendAsync(streamState.Name, ObtainApiKey(), content, timeout, cancellationToken) .ConfigureAwait(false); var status = response.Status; if (statusAnalyzer.ShouldDropStoredRecords(status)) { RequestGarbageCollection(batch); if (status == HerculesStatus.Success) { streamState.Statistics.ReportSuccessfulSending(recordsCount, recordsSize); } else { streamState.Statistics.ReportSendingFailure(recordsCount, recordsSize); } } if (status == HerculesStatus.Success) { LogBatchSendSuccess(recordsCount, recordsSize, watch.Elapsed); } else { LogBatchSendFailure(recordsCount, recordsSize, status, response.ErrorDetails); } return(status); } }