Add scheduled job to process pending jobs in LeaveProcessJobStatusRepository

This commit is contained in:
Suphonchai Phoonsawat 2026-03-30 10:06:21 +07:00
parent 91e6b1b35b
commit 8732c34564
2 changed files with 5 additions and 5 deletions

View file

@ -128,11 +128,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
}
public async Task ProcessPendingJobsAsync(CancellationToken cancellationToken = default)
public async Task ProcessPendingJobsAsync()
{
// กำหนด timeout เป็น 60 นาที
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(60));
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
var pendingJobs = await GetPendingOrProcessingJobsAsync();
@ -145,7 +143,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
await UpdateToProcessingAsync(job.Id);
// ทำงานที่ต้องการที่นี่ (เช่น เรียก API, ประมวลผลข้อมูล ฯลฯ)
await ProcessTaskAsync(job.RootDnaId, combinedCts.Token);
await ProcessTaskAsync(job.RootDnaId);
// อัปเดตสถานะเป็น Completed
await UpdateToCompletedAsync(job.Id);

View file

@ -190,6 +190,8 @@ if (manager != null)
manager.AddOrUpdate("ปรับปรุงรอบการลงเวลาทำงาน", Job.FromExpression<UserDutyTimeRepository>(x => x.UpdateUserDutyTime()), "0 1 * * *", bangkokTimeZone);
// ทำความสะอาดข้อมูล CheckIn Job Status ที่เก่ากว่า 30 วัน - รันทุกวันเวลา 02:00 น.
manager.AddOrUpdate("ทำความสะอาดข้อมูล CheckIn Job Status", Job.FromExpression<CheckInJobStatusRepository>(x => x.CleanupOldJobsAsync(30)), "0 2 * * *", bangkokTimeZone);
manager.AddOrUpdate("ประมวลผลงานที่ค้างอยู่ในสถานะ Pending หรือ Processing", Job.FromExpression<LeaveProcessJobStatusRepository>(x => x.ProcessPendingJobsAsync()), "0 3 * * *", bangkokTimeZone);
}
// apply migrations