//using FastEndpoints; //using FrameworkDAL.CustomCode.SchedulerTaskGenerator; //using FrameworkDAL.DTO.SchedulerTaskGenerator; //using GB5Shared.DTO.Framework.Login; //using GB5Shared.DTO.Framework.ResponseStandard; //using GB5Shared.FastEndPoint; //using Microsoft.Extensions.Logging; //using static GB5Shared.GB5Constant.Constant; //namespace FrameworkSL.Endpoints.SchedulerTaskGenerator //{ // /// // /// Scheduler Job Consumer // /// ---------------------- // /// ✔ Consumes from Dapr RabbitMQ // /// ✔ Executes business logic // /// ✔ Updates LASTRUNTIME only on success // /// ✔ HTTP 500 triggers Dapr retry / DLQ // /// // public sealed class ExecuteSchedulerJob // : BaseEndpoint> // { // private readonly ISchedulerTaskDAL _schedulerTaskDAL; // private readonly ILogger _logger; // public ExecuteSchedulerJob( // ISchedulerTaskDAL schedulerTaskDAL, // ILogger logger) // { // _schedulerTaskDAL = schedulerTaskDAL; // _logger = logger; // } // public override void Configure() // { // // 🔥 REQUIRED: Without this Dapr CANNOT invoke the endpoint // Verbs(Http.POST); // Routes("/scheduler/execute"); // // GB5 handles auth internally // // No AllowAnonymous() here // } // protected override async Task> ExecuteAsync( // SchedulerTaskDTO task, // LoginDTO login, // CancellationToken ct) // { // _logger.LogInformation( // "▶️ Scheduler Job START | JobId={JobId}", // task.JobId); // try // { // // 🔹 Execute actual job logic // await ExecuteBusinessLogic(task, login, ct); // // ✅ Update LASTRUNTIME ONLY after success // await _schedulerTaskDAL.MarkJobAsPublishedAsync( // task.JobId, // login); // _logger.LogInformation( // "✅ Scheduler Job SUCCESS | JobId={JobId}", // task.JobId); // // ✔ HTTP 200 → Dapr ACK // return await GB5Shared.ResponseStandard.Response // .CreateSuccessResponse( // "Scheduler job executed successfully", // CacheKeyLevel.NOT_REQUIRED, // login); // } // catch (Exception ex) // { // _logger.LogError( // ex, // "❌ Scheduler Job FAILED | JobId={JobId}", // task.JobId); // // ❌ HTTP 500 → Dapr retry / DLQ // return await GB5Shared.ResponseStandard.Response // .CreateExceptionError( // ex, // CacheKeyLevel.NOT_REQUIRED, // login, // ex.Message, // 500); // } // } // private static async Task ExecuteBusinessLogic( // SchedulerTaskDTO task, // LoginDTO login, // CancellationToken ct) // { // // TODO: real business logic (report, mail, export, API call) // await Task.Delay(50, ct); // } // } //}