Exemple #1
0
 /// <summary>
 /// Throws a <see cref="HerculesException"/> if given <paramref name="status"/> is not <see cref="IsSuccessful"/>.
 /// </summary>
 public static void EnsureSuccess(this HerculesStatus status)
 {
     if (IsSuccessful(status))
     {
         throw new HerculesException(status);
     }
 }
Exemple #2
0
        public bool ShouldDropStoredRecords(HerculesStatus status)
        {
            switch (status)
            {
            case HerculesStatus.Success:
            case HerculesStatus.IncorrectRequest:
            case HerculesStatus.RequestTooLarge:
                return(true);
            }

            return(false);
        }
        private TimeSpan MeasureWaitDelay(HerculesStatus lastStatus, TimeSpan?lastLatency = null)
        {
            var sendResult = new StreamSendResult(lastStatus, lastLatency ?? TimeSpan.Zero);

            var waitTask = planner.WaitForNextSendAsync(sendResult, cancellation.Token);

            if (waitTask.IsCompleted)
            {
                return(TimeSpan.Zero);
            }

            var watch = Stopwatch.StartNew();

            waitTask.GetAwaiter().GetResult();

            return(watch.Elapsed);
        }
Exemple #4
0
        public bool ShouldIncreaseSendPeriod(HerculesStatus status)
        {
            switch (status)
            {
            case HerculesStatus.StreamNotFound:
            case HerculesStatus.Unauthorized:
            case HerculesStatus.InsufficientPermissions:
            case HerculesStatus.Throttled:
            case HerculesStatus.Timeout:
            case HerculesStatus.NetworkError:
            case HerculesStatus.ServerError:
            case HerculesStatus.UnknownError:
                return(true);
            }

            return(false);
        }
Exemple #5
0
        private static void ExtractErrorMessage(Response response, HerculesStatus status, out string errorMessage)
        {
            errorMessage = null;

            if (status == HerculesStatus.Success)
            {
                return;
            }

            if (!response.HasContent)
            {
                return;
            }

            if (response.Content.Length > MaximumErrorMessageLength)
            {
                return;
            }

            errorMessage = response.Content.ToString();
        }
Exemple #6
0
        private void LogBatchSendFailure(int recordsCount, long recordsSize, HerculesStatus status, string error)
        {
            if (status == HerculesStatus.Canceled)
            {
                return;
            }

            log.Warn(
                "Failed to send {RecordsCount} record(s) of size {RecordsSize} to stream '{StreamName}'. " +
                "Status: {Status}. Error: '{Error}'.",
                recordsCount,
                recordsSize,
                streamState.Name,
                status,
                error);

            if (statusAnalyzer.ShouldDropStoredRecords(status))
            {
                log.Warn("Dropped {RecordsCount} record(s) as a result of non-retriable failure.", recordsCount);
            }
        }
Exemple #7
0
 public RawReadStreamResult(HerculesStatus status, RawReadStreamPayload payload, [CanBeNull] string errorDetails = null)
     : base(status, payload, errorDetails)
 {
 }
Exemple #8
0
 public DeleteTimelineResult(HerculesStatus status, [CanBeNull] string errorDetails = null)
     : base(status, errorDetails)
 {
 }
 public void ShouldIncreaseSendPeriod_should_correctly_react_to_given_status(HerculesStatus status, bool expectedResult)
 {
     analyzer.ShouldIncreaseSendPeriod(status).Should().Be(expectedResult);
 }
Exemple #10
0
 public HerculesException(HerculesStatus status, string details = null)
     : this($"Hercules operation has failed with status '{status}'. {details}")
 {
 }
 public StreamSendResult(HerculesStatus status, TimeSpan elapsed)
 {
     Status  = status;
     Elapsed = elapsed;
 }
 private static StreamSendResult SendResult(HerculesStatus status)
 => new StreamSendResult(status, TimeSpan.Zero);
Exemple #13
0
 public HerculesResult(HerculesStatus status, TPayload payload, [CanBeNull] string errorDetails = null)
     : base(status, errorDetails)
 {
     this.payload = payload;
 }
Exemple #14
0
 private static bool IsHealthyStatus(HerculesStatus status) => status == HerculesStatus.Success || status == HerculesStatus.Canceled;
 public ReadTimelineResult(HerculesStatus status, ReadTimelinePayload payload, [CanBeNull] string errorDetails = null)
     : base(status, payload, errorDetails)
 {
 }
 public HerculesResult(HerculesStatus status, [CanBeNull] string errorDetails = null)
 {
     Status       = status;
     ErrorDetails = errorDetails;
 }
 public InsertEventsResult(HerculesStatus status, [CanBeNull] string errorDetails = null)
     : base(status, errorDetails)
 {
 }
 public void ShouldDropStoredRecords_should_correctly_react_to_given_status(HerculesStatus status, bool expectedResult)
 {
     analyzer.ShouldDropStoredRecords(status).Should().Be(expectedResult);
 }
 public void Should_correctly_map_given_stream_response_code(ResponseCode code, HerculesStatus expectedStatus)
 {
     Analyze(code).Should().Be(expectedStatus);
 }
 public void Should_correctly_map_given_timeline_response_code(ResponseCode code, HerculesStatus expectedStatus)
 {
     Analyze(code, context: ResponseAnalysisContext.Timeline).Should().Be(expectedStatus);
 }
Exemple #21
0
 /// <summary>
 /// Returns <c>true</c> if given <paramref name="status"/> is <see cref="HerculesStatus.Success"/> or <c>false</c> otherwise.
 /// </summary>
 public static bool IsSuccessful(this HerculesStatus status) =>
 status == HerculesStatus.Success;