chore
This commit is contained in:
54
Atomx.Core/Jos/ResetCacheJob.cs
Normal file
54
Atomx.Core/Jos/ResetCacheJob.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Atomx.Data;
|
||||
using Atomx.Data.CacheServices;
|
||||
using Hangfire;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Atomx.Core.Jos
|
||||
{
|
||||
public class ResetCacheJob
|
||||
{
|
||||
readonly ILogger<ResetCacheJob> _logger;
|
||||
readonly DataContext _dbContext;
|
||||
readonly ICacheService _cacheService;
|
||||
public ResetCacheJob(ILogger<ResetCacheJob> logger, DataContext dataContext, ICacheService cacheService)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dataContext;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果任务失败,重试 3 次,超过后删除任务,60 秒内不允许并发执行
|
||||
/// </summary>
|
||||
[AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||
[DisableConcurrentExecution(60)]
|
||||
public async Task ResetStateProvinceAndAreaTree(long countryId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _cacheService.GetAreaTree(countryId, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error resetting cache for countryId: {CountryId}", countryId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果任务失败,重试 3 次,超过后删除任务,60 秒内不允许并发执行
|
||||
/// </summary>
|
||||
[AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||
[DisableConcurrentExecution(60)]
|
||||
public async Task ResetCountry()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _cacheService.GetCountries(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error resetting country cache");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user