Skip to content

Commit

Permalink
Merge pull request #361 from bcgov/june
Browse files Browse the repository at this point in the history
chore: peformance
  • Loading branch information
ychung-mot authored Jun 4, 2024
2 parents f9169c4 + d245a0b commit 02526f0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
7 changes: 3 additions & 4 deletions server/StrDss.Data/Repositories/UploadDeliveryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IUploadDeliveryRepository
{
Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, long orgId, string hashValue);
Task AddUploadDeliveryAsync(DssUploadDelivery upload);
Task<List<DssUploadDelivery>> GetRentalReportUploadsToProcessAsync();
Task<DssUploadDelivery?> GetRentalReportUploadToProcessAsync();
Task<DssUploadDelivery?> GetRentalListingErrorLines(long uploadId);
Task<DssUploadLine?> GetUploadLineAsync(long uploadId, string orgCd, string listingId);
}
Expand All @@ -35,16 +35,15 @@ public async Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, lo
.AnyAsync(x => x.ReportPeriodYm == periodYm && x.ProvidingOrganizationId == orgId && x.SourceHashDsc == hashValue);
}

public async Task<List<DssUploadDelivery>> GetRentalReportUploadsToProcessAsync()
public async Task<DssUploadDelivery?> GetRentalReportUploadToProcessAsync()
{
return await _dbSet
//.Include(x => x.DssUploadLines.Where(line => !line.IsProcessed))
.Include(x => x.ProvidingOrganization)
.Where(x => x.DssUploadLines.Any(line => !line.IsProcessed))
.OrderBy(x => x.ProvidingOrganizationId)
.ThenBy(x => x.ReportPeriodYm)
.ThenBy(x => x.UpdDtm) //Users can upload the same listing multiple times. The processing of these listings follows a first-come, first-served approach.
.ToListAsync();
.FirstOrDefaultAsync();
}

public async Task<DssUploadLine?> GetUploadLineAsync(long uploadId, string orgCd, string listingId)
Expand Down
2 changes: 1 addition & 1 deletion server/StrDss.Hangfire/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
app.UseHangfireDashboard();

// make sure this is after app.UseHangfireDashboard()
RecurringJob.AddOrUpdate<HangfireJobs>("Process Rental Listing Report", job => job.ProcessRentalListingReports(), "*/10 * * * *");
RecurringJob.AddOrUpdate<HangfireJobs>("Process Rental Listing Report", job => job.ProcessRentalListingReports(), "0 0/3 * * *");
RecurringJob.AddOrUpdate<HangfireJobs>("Process Takedown Request Batch Emails", job => job.ProcessTakedownRequestBatchEmails(), "50 6 * * *");

app.Run();
2 changes: 1 addition & 1 deletion server/StrDss.Service/Hangfire/HangfireJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public HangfireJobs(IRentalListingReportService listingService, IDelistingServic
[AutomaticRetry(Attempts = 0)]
public async Task ProcessRentalListingReports()
{
await _linstingService.ProcessRentalReportUploadsAsync();
await _linstingService.ProcessRentalReportUploadAsync();
}

[Queue("default")]
Expand Down
1 change: 1 addition & 0 deletions server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void OnCreating(CreatingContext context)
if (jobFingerprint != fingerprint)
continue;

Console.WriteLine($"Cancelling {fingerprint} at {DateTime.UtcNow}");
context.Canceled = true;

return;
Expand Down
8 changes: 4 additions & 4 deletions server/StrDss.Service/RentalListingReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IRentalListingReportService
{
Task<Dictionary<string, List<string>>> ValidateAndParseUploadAsync(string reportPeriod, long orgId, string hashValue, TextReader textReader, List<DssUploadLine> lines);
Task<Dictionary<string, List<string>>> UploadRentalReport(string reportPeriod, long orgId, Stream stream);
Task ProcessRentalReportUploadsAsync();
Task ProcessRentalReportUploadAsync();
Task<PagedDto<RentalUploadHistoryViewDto>> GetRentalListingUploadHistory(long? platformId, int pageSize, int pageNumber, string orderBy, string direction);
Task<byte[]?> GetRentalListingErrorFile(long uploadId);
}
Expand Down Expand Up @@ -288,11 +288,11 @@ private bool CheckCommonMandatoryFields(string[] headers, string[] mandatoryFiel
return errors.Count == 0;
}

public async Task ProcessRentalReportUploadsAsync()
public async Task ProcessRentalReportUploadAsync()
{
var uploads = await _uploadRepo.GetRentalReportUploadsToProcessAsync();
var upload = await _uploadRepo.GetRentalReportUploadToProcessAsync();

foreach (var upload in uploads)
if (upload != null)
{
await ProcessRentalReportUploadAsync(upload);
}
Expand Down

0 comments on commit 02526f0

Please sign in to comment.