using System.Text.Json; using Dapr; using EntitlementBLL.Onboarding; using Microsoft.AspNetCore.Mvc; namespace EntitlementSL.Subscriptions; // sqlworkbench.changerequest.progress -> PushDdlProgressForAwaitingJobsAsync (tracker §37 // Decision 2). Published by SwBLL.ChangeRequest.ChangeRequestBLL.ExecuteDdlCr every N scripts // while a ClientProvisioning CR's linked DDL is being applied. // // Binds the raw payload as JsonElement and never reads it — same reasoning, and same "pubsub" // Dapr component, as ClientProvisioningExecutedSubscriber's own identical choice: EventLogPublish // wraps the real payload in a double-JSON-encoded PublishDTO envelope that's fragile to bind // directly. This event is used purely as a wake-up signal — PushDdlProgressForAwaitingJobsAsync // re-reads the real, live ScriptsDone/ScriptsTotal straight from SqlWorkbench for every job still // waiting on a CR, rather than trusting anything about which CR/how far along the payload claims. [ApiController] public class ClientProvisioningProgressSubscriber : ControllerBase { private readonly IClientOnboardingOrchestratorBLL _Orchestrator; private readonly ILogger _Logger; public ClientProvisioningProgressSubscriber( IClientOnboardingOrchestratorBLL orchestrator, ILogger logger) { _Orchestrator = orchestrator; _Logger = logger; } [Topic("pubsub", "sqlworkbench.changerequest.progress")] [HttpPost("/lic/Subscriptions/ClientProvisioningProgress")] public async Task HandleAsync([FromBody] JsonElement payload, CancellationToken ct) { try { await _Orchestrator.PushDdlProgressForAwaitingJobsAsync(ct); return Ok(); } catch (Exception ex) { _Logger.LogError(ex, "ClientProvisioningProgressSubscriber failed to relay DDL progress."); return StatusCode(500, ex.Message); } } }