From f081034e36e4741aa8a751bd7268fcbd959dd0d9 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 11 Nov 2025 10:40:49 +0700 Subject: [PATCH] =?UTF-8?q?fix=20hangfire=20=E0=B9=81=E0=B8=A2=E0=B8=81=20?= =?UTF-8?q?job=20=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=88=E0=B8=B2=E0=B8=81?= =?UTF-8?q?=E0=B8=81=E0=B8=B1=E0=B8=99=20=E0=B9=81=E0=B8=A5=E0=B8=B0?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=80=E0=B8=A3=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=AA=E0=B9=88?= =?UTF-8?q?=E0=B8=87=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/GenericRepository.cs | 1 + .../Repositories/UserProfileRepository.cs | 4 ++-- .../Controllers/InsigniaRequestController.cs | 2 +- BMA.EHR.Insignia/Program.cs | 21 +++++++++++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index 1f10ca37..b5519c15 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -113,6 +113,7 @@ namespace BMA.EHR.Application.Repositories { try { + var json = JsonConvert.SerializeObject(body); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); //stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index df2fe6b0..2b420e5d 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -146,7 +146,7 @@ namespace BMA.EHR.Application.Repositories // สร้าง HTTP content //var body = new StringContent(bodyJson, Encoding.UTF8, "application/json"); - var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey); + var apiResult = await PostExternalAPIAsync(apiPath, accessToken ?? "", body, apiKey); if (apiResult != null) { @@ -157,7 +157,7 @@ namespace BMA.EHR.Application.Repositories return null; } - catch + catch(Exception ex) { throw; } diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index 211a651a..005f9882 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -290,7 +290,7 @@ namespace BMA.EHR.Insignia.Service.Controllers [AllowAnonymous] public async Task> Test() { - await _insigniaReportRepository.CalInsigniaRequestBkkByType("officer"); + await _insigniaReportRepository.CalInsigniaRequestBkkByType("employee"); return Success(); } diff --git a/BMA.EHR.Insignia/Program.cs b/BMA.EHR.Insignia/Program.cs index 5352e7b3..a4dd716a 100644 --- a/BMA.EHR.Insignia/Program.cs +++ b/BMA.EHR.Insignia/Program.cs @@ -125,9 +125,14 @@ var builder = WebApplication.CreateBuilder(args); DashboardJobListLimit = 50000, TransactionTimeout = TimeSpan.FromMinutes(1), InvisibilityTimeout = TimeSpan.FromHours(3), - TablesPrefix = "Hangfire" + TablesPrefix = "Hangfire_Insignia" }))); - builder.Services.AddHangfireServer(); + builder.Services.AddHangfireServer(options => + { + options.ServerName = "Insignia-Server"; // ← ระบุชื่อ server + options.WorkerCount = 5; // ← + options.Queues = new[] { "insignia" }; // ← worker จะรันเฉพาะ queue "insignia" + }); // RabbitMQ @@ -193,7 +198,11 @@ var app = builder.Build(); x => x.CalculateInsigniaRequestBkkByType("officer"), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]) - 5, Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), - TimeZoneInfo.Local + new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local, + QueueName = "insignia" // ← กำหนด queue + } ); RecurringJob.AddOrUpdate( @@ -201,7 +210,11 @@ var app = builder.Build(); x => x.CalculateInsigniaRequestBkkByType("employee"), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]) - 4, Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), - TimeZoneInfo.Local + new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local, + QueueName = "insignia" // ← กำหนด queue + } ); // apply migrations