Add cancellation token support and extend timeout to 30 minutes for external API calls
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m19s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m19s
This commit is contained in:
parent
0a170fd259
commit
659e06a08d
7 changed files with 76 additions and 76 deletions
|
|
@ -61,9 +61,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
return await _dbContext.Set<DutyTime>().Where(x => x.IsActive).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<DutyTime?> GetDefaultAsync()
|
||||
public async Task<DutyTime?> GetDefaultAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _dbContext.Set<DutyTime>().Where(x => x.IsDefault).FirstOrDefaultAsync();
|
||||
// กำหนด timeout เป็น 30 นาที
|
||||
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(30));
|
||||
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
|
||||
return await _dbContext.Set<DutyTime>().Where(x => x.IsDefault).FirstOrDefaultAsync(combinedCts.Token);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -101,14 +101,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
return data;
|
||||
}
|
||||
|
||||
public async Task<UserDutyTime?> GetLastEffectRound(Guid profileId, DateTime? effectiveDate = null)
|
||||
public async Task<UserDutyTime?> GetLastEffectRound(Guid profileId, DateTime? effectiveDate = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// กำหนด timeout เป็น 30 นาที
|
||||
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(30));
|
||||
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
|
||||
effectiveDate ??= DateTime.Now;
|
||||
var data = await _dbContext.Set<UserDutyTime>()
|
||||
.Where(x => x.ProfileId == profileId)
|
||||
.Where(x => x.EffectiveDate.Value.Date <= effectiveDate.Value.Date)
|
||||
.OrderByDescending(x => x.EffectiveDate)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(combinedCts.Token);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,12 +74,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
return data;
|
||||
}
|
||||
|
||||
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId)
|
||||
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// กำหนด timeout เป็น 30 นาที
|
||||
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(30));
|
||||
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
|
||||
|
||||
var data = await _dbContext.Set<UserTimeStamp>()
|
||||
.Where(u => u.KeycloakUserId == keycloakId)
|
||||
.OrderByDescending(u => u.CheckIn)
|
||||
.FirstOrDefaultAsync();
|
||||
.FirstOrDefaultAsync(combinedCts.Token);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue