protected override HealthStatus GetBatchStatus()

in src/Epam.Kafka.PubSub/Subscription/HealthChecks/SubscriptionHealthCheck.cs [42:84]


    protected override HealthStatus GetBatchStatus()
    {
        TimeSpan handlerTimespan = this.UtcNow - this._monitor.Batch.TimestampUtc;

        if (this._monitor.Batch.Value is BatchStatus.None
            or BatchStatus.Reading
            or BatchStatus.Finished
            or BatchStatus.Commiting)
        {
            TimeSpan batchTimespan = this.UtcNow - this._monitor.Result.TimestampUtc;

            if (handlerTimespan > this.Options.HealthChecksThresholdBatch)
            {
                return HealthStatus.Unhealthy;
            }

            if (this._monitor.Result.Value == SubscriptionBatchResult.NotAssigned &&
                batchTimespan > this.Options.HealthChecksThresholdBatch)
            {
                return HealthStatus.Degraded;
            }
        }

        if (this._monitor.Batch.Value == BatchStatus.Running)
        {
            if (handlerTimespan > this.Options.HandlerTimeout)
            {
                return HealthStatus.Unhealthy;
            }
        }

        if (this._monitor.Batch.Value == BatchStatus.Queued)
        {
            if (this.QueuedHealthStatus(handlerTimespan, out HealthStatus healthStatus)) return healthStatus;
        }

        if (this._monitor.Result.Value == SubscriptionBatchResult.Error)
        {
            return HealthStatus.Degraded;
        }

        return HealthStatus.Healthy;
    }