Skip to content

Commit 9152fa4

Browse files
change
1 parent aa19de2 commit 9152fa4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/Spd.Manager.ScheduleJob/Contract.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IScheduleJobManager
99
}
1010

1111
#region run schedule job session
12-
public record RunScheduleJobSessionCommand(Guid JobSessionId, int ConcurrentRequests) : IRequest<Unit>;
13-
public record RunMonthlyInvoiceJobCommand(Guid JobSessionId, int ConcurrentRequests) : IRequest<Unit>;
12+
public record RunScheduleJobSessionCommand(Guid JobSessionId, int ConcurrentRequests = 3) : IRequest<Unit>;
13+
public record RunMonthlyInvoiceJobCommand(Guid JobSessionId, int ConcurrentRequests = 3) : IRequest<Unit>;
1414
#endregion
1515
}

src/Spd.Manager.ScheduleJob/ScheduleJobManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task<Unit> Handle(RunScheduleJobSessionCommand cmd, CancellationTok
7777
}
7878

7979
Stopwatch stopwatch = Stopwatch.StartNew();
80-
using var cts = new CancellationTokenSource(); // no timeout
80+
using var cts = new CancellationTokenSource(); // no timeout, this is the resolve for mysteriously cancelled requests
8181
//request will from bcgov_schedulejob
8282
RunJobRequest request = new RunJobRequest
8383
{
@@ -86,7 +86,7 @@ public async Task<Unit> Handle(RunScheduleJobSessionCommand cmd, CancellationTok
8686
PrimaryEntityFilterStr = "statecode eq 0 and spd_eligibleforcreditpayment eq 100000001",
8787
PrimaryEntityIdName = "accountid"
8888
};
89-
var result = await _generalizeScheduleJobRepository.RunJobsAsync(request, cts.Token);
89+
var result = await _generalizeScheduleJobRepository.RunJobsAsync(request, cmd.ConcurrentRequests, cts.Token);
9090
stopwatch.Stop();
9191

9292
//update result in JobSession

src/Spd.Resource.Repository.JobSchedule/GeneralizeScheduleJob/Contract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Spd.Resource.Repository.JobSchedule.GeneralizeScheduleJob
22
{
33
public interface IGeneralizeScheduleJobRepository
44
{
5-
public Task<IEnumerable<ResultResp>> RunJobsAsync(RunJobRequest request, CancellationToken cancellationToken);
5+
public Task<IEnumerable<ResultResp>> RunJobsAsync(RunJobRequest request, int ConcurrentRequests, CancellationToken cancellationToken);
66
}
77

88
public record RunJobRequest

src/Spd.Resource.Repository.JobSchedule/GeneralizeScheduleJob/GeneralizeScheduleJobRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public GeneralizeScheduleJobRepository(IDynamicsContextFactory ctx,
7575
// return results;
7676
//}
7777

78-
public async Task<IEnumerable<ResultResp>> RunJobsAsync(RunJobRequest request, CancellationToken ct)
78+
public async Task<IEnumerable<ResultResp>> RunJobsAsync(RunJobRequest request, int concurrentRequests, CancellationToken ct)
7979
{
8080
string primaryEntityName = request.PrimaryEntityName;
8181
string filterStr = request.PrimaryEntityFilterStr;
@@ -87,7 +87,7 @@ public async Task<IEnumerable<ResultResp>> RunJobsAsync(RunJobRequest request, C
8787
Type entityType = GetEntityTypeByName(primaryTypeName);
8888
var data = await CallGetAllPrimaryEntityDynamicAsync(entityType, primaryEntityName, filterStr, ct);
8989

90-
using var semaphore = new SemaphoreSlim(10); // Limit to 10 concurrent requests
90+
using var semaphore = new SemaphoreSlim(concurrentRequests); // Limit to 10 concurrent requests
9191

9292
var tasks = data.Select(async a =>
9393
{
@@ -192,8 +192,8 @@ private async Task<IEnumerable<T>> GetAllPrimaryEntityAsync<T>(string primaryEnt
192192
var property = _context.GetType().GetProperty(primaryEntityName);
193193
if (property == null) throw new Exception("Property not found.");
194194

195-
dynamic query = property.GetValue(_context) as DataServiceQuery;
196-
query.AddQueryOption("$filter", filterStr)
195+
var query = property.GetValue(_context) as DataServiceQuery<T>;
196+
query = query.AddQueryOption("$filter", filterStr)
197197
.IncludeCount();
198198

199199
var allEntities = new List<T>();

0 commit comments

Comments
 (0)