Skip to content

Commit

Permalink
Merge pull request #478 from bcgov/yj
Browse files Browse the repository at this point in the history
Yj
  • Loading branch information
ychung-mot authored Jul 18, 2024
2 parents 9031523 + 01f6721 commit c67462c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/StrDss.Data/Repositories/RentalListingRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface IRentalListingRepository
Task ConfirmAddressAsync(long rentalListingId);
Task<DssRentalListing> UpdateAddressAsync(UpdateListingAddressDto dto);
DateTime GetLatestRentalListingExportTime();
Task<bool> IsListingUploadProcessRunning();
}
public class RentalListingRepository : RepositoryBase<DssRentalListingVw>, IRentalListingRepository
{
Expand Down Expand Up @@ -552,5 +553,11 @@ public DateTime GetLatestRentalListingExportTime()
return DateTime.UtcNow.AddDays(-1);
}
}

public async Task<bool> IsListingUploadProcessRunning()
{
return await _dbContext.DssUploadLines
.AnyAsync(x => x.IncludingUploadDelivery.UploadDeliveryType == "rental_report" && x.IsProcessed == false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Hangfire.Common;
using Hangfire.Server;
using Hangfire;

namespace StrDss.Service.Hangfire
{
/// <summary>
/// Usage:
///
/// [DisableConcurrentExecution(timeoutInSeconds: 10 * 60)]
///
/// </summary>

public class DisableConcurrentExecutionAttribute : JobFilterAttribute, IServerFilter
{
private readonly int _timeoutInSeconds;

public DisableConcurrentExecutionAttribute(int timeoutInSeconds)
{
_timeoutInSeconds = timeoutInSeconds;
}

public void OnPerforming(PerformingContext filterContext)
{
var jobId = filterContext.BackgroundJob.Id;
var connection = JobStorage.Current.GetConnection();
var currentJob = connection.GetJobData(jobId);

if (currentJob != null && currentJob.State == "Processing")
{
throw new InvalidOperationException("This job is already being processed.");
}
}

public void OnPerformed(PerformedContext filterContext)
{
}
}
}
8 changes: 8 additions & 0 deletions server/StrDss.Service/RentalListingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public async Task CreateRentalListingExportFiles()
return;
}

var isListingUploadProcessRunning = await _listingRepo.IsListingUploadProcessRunning();

if (isListingUploadProcessRunning)
{
_logger.LogInformation("Skipping CreateRentalListingExportFiles: Rental Listing Upload Process is running");
return;
}

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

Expand Down

0 comments on commit c67462c

Please sign in to comment.