forked from gongxuegit/tiku-backend.net
feat(security): complete capability messaging workflows
This commit is contained in:
@@ -45,6 +45,16 @@ public sealed class HealthController(
|
||||
var outboxPending = database
|
||||
? await dbContext.Set<OutboxMessage>().CountAsync(cancellationToken)
|
||||
: -1;
|
||||
var outboxOldestSentTime = database
|
||||
? await dbContext.Set<OutboxMessage>()
|
||||
.Select(message => (DateTime?)message.SentTime)
|
||||
.MinAsync(cancellationToken)
|
||||
: null;
|
||||
var outboxOldestAgeSeconds = outboxOldestSentTime is null
|
||||
? 0
|
||||
: Math.Max(0, (DateTimeOffset.UtcNow - new DateTimeOffset(outboxOldestSentTime.Value)).TotalSeconds);
|
||||
var outboxAlert = outboxPending >= messagingOptions.OutboxBacklogAlertCount ||
|
||||
outboxOldestAgeSeconds >= messagingOptions.OutboxOldestMessageAlertSeconds;
|
||||
var ready = database && redis && rabbitMq;
|
||||
var response = new
|
||||
{
|
||||
@@ -52,7 +62,14 @@ public sealed class HealthController(
|
||||
database,
|
||||
redis = new { configured = redisSecurityStore.IsConfigured, ready = redis },
|
||||
rabbitMq = new { configured = messagingOptions.IsConfigured, ready = rabbitMq },
|
||||
outbox = new { pending = outboxPending },
|
||||
outbox = new
|
||||
{
|
||||
pending = outboxPending,
|
||||
oldestAgeSeconds = Math.Round(outboxOldestAgeSeconds, 1),
|
||||
alert = outboxAlert,
|
||||
backlogAlertCount = messagingOptions.OutboxBacklogAlertCount,
|
||||
oldestMessageAlertSeconds = messagingOptions.OutboxOldestMessageAlertSeconds
|
||||
},
|
||||
checkedAt = DateTimeOffset.UtcNow
|
||||
};
|
||||
return ready ? Ok(response) : StatusCode(StatusCodes.Status503ServiceUnavailable, response);
|
||||
|
||||
Reference in New Issue
Block a user