Skip to content

Commit

Permalink
Merge pull request #477 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: Throttle export frequency: Prevent running if less than 2 hour…
  • Loading branch information
ychung-mot authored Jul 18, 2024
2 parents 862d204 + f792d6c commit 9031523
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/StrDss.Data/Repositories/RentalListingRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface IRentalListingRepository
Task<RentalListingExtractDto?> GetRetalListingExportAsync(long extractId);
Task ConfirmAddressAsync(long rentalListingId);
Task<DssRentalListing> UpdateAddressAsync(UpdateListingAddressDto dto);
DateTime GetLatestRentalListingExportTime();
}
public class RentalListingRepository : RepositoryBase<DssRentalListingVw>, IRentalListingRepository
{
Expand Down Expand Up @@ -539,5 +540,17 @@ public async Task<DssRentalListing> UpdateAddressAsync(UpdateListingAddressDto d

return listing;
}

public DateTime GetLatestRentalListingExportTime()
{
if (_dbContext.DssRentalListingExtracts.Any())
{
return _dbContext.DssRentalListingExtracts.Max(x => x.UpdDtm);
}
else
{
return DateTime.UtcNow.AddDays(-1);
}
}
}
}
11 changes: 11 additions & 0 deletions server/StrDss.Service/RentalListingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ private void ProcessHosts(RentalListingViewDto listing, bool clearHosts = false)

public async Task CreateRentalListingExportFiles()
{
// Throttle export frequency: Prevent running if less than 2 hours since last export
var latestExtractTime = _listingRepo.GetLatestRentalListingExportTime();
var currentTime = DateTime.UtcNow;
var timeDifference = currentTime - latestExtractTime;

if (timeDifference < TimeSpan.FromHours(2))
{
_logger.LogInformation("Skipping CreateRentalListingExportFiles: Last export was {TimeDifference:hh\\:mm\\:ss} ago, less than 2 hours", timeDifference);
return;
}

var listingIds = await _listingRepo.GetRentalListingIdsToExport();
var headers = RentalListingExport.GetHeadersAsCsv();

Expand Down

0 comments on commit 9031523

Please sign in to comment.