Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Functions/Queue/TenantAutoApproveQueueFunction.cs
T
Oliver Kieselbach 86fdc5aca9 backend: stateless queue consumers become [QueueTrigger] functions; webhooks go through a queue; poll loop receives one message at a time
Audit 2026-09-05 F01/F02. Analyze, VulnerabilityCorrelate, TenantAutoApprove,
IndexReconcile and ImeMsiArchive are now host-managed queue functions under
Functions/Queue bound to the DataStorage connection (identity-based, resolved
by the host): the Flex scale controller wakes an instance for a message, the
host renews the lease and owns the retry/poison ladder. The four cascade
workers with lease/CAS state stay self-polling BackgroundServices; their base
now receives one message per poll so waiting messages can no longer expire
under another worker. Terminal enrollment alerts and hardware-rejection alerts
are enqueued on notification-dispatch (channel ids only, resolved at send
time) instead of fire-and-forget sends the host could drop on scale-in.
Requires the app setting DataStorage__queueServiceUri before deploy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 02:52:37 +02:00

46 lines
1.7 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using AutopilotMonitor.Functions.Services.Activation;
using AutopilotMonitor.Functions.Services.Queueing;
using AutopilotMonitor.Shared;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace AutopilotMonitor.Functions.Functions.Queue
{
/// <summary>
/// Host-managed consumer of the <c>tenant-auto-approve</c> queue (lease, retry ladder and
/// poison move owned by the Functions host — see <see cref="AnalyzeOnEnrollmentEndQueueFunction"/>).
/// The producer's ~1-minute visibility delay still applies; every decision lives in
/// <see cref="TenantAutoApproveHandler"/>.
/// </summary>
public sealed class TenantAutoApproveQueueFunction
{
private readonly TenantAutoApproveHandler _handler;
private readonly ILogger<TenantAutoApproveQueueFunction> _logger;
public TenantAutoApproveQueueFunction(
TenantAutoApproveHandler handler,
ILogger<TenantAutoApproveQueueFunction> logger)
{
_handler = handler;
_logger = logger;
}
[Function("TenantAutoApproveQueue")]
public Task Run(
[QueueTrigger(Constants.QueueNames.TenantAutoApprove, Connection = Constants.QueueNames.TriggerConnection)]
QueueMessage message,
CancellationToken cancellationToken)
{
if (!QueueEnvelopeReader.TryRead<TenantAutoApproveEnvelope>(
message, _logger, out var envelope,
validate: e => !string.IsNullOrWhiteSpace(e.TenantId)))
return Task.CompletedTask;
return _handler.HandleAsync(envelope, cancellationToken);
}
}
}