From 8a1ff0edf9c14c8c25859f2d376a60d252026452 Mon Sep 17 00:00:00 2001 From: yxw <17074267@qq.com> Date: Fri, 12 Dec 2025 16:18:27 +0800 Subject: [PATCH] chore --- Atomx.Core/Atomx.Core.csproj | 1 + Atomx.Core/Jos/LocalizationJob.cs | 21 +++++--- Atomx.Core/Jos/SendVerificationCodeJob.cs | 28 ++++++++++ Atomx.Core/Services/BackgroundJobsService.cs | 20 +++++++- .../CacheServices/LocalizationCacheService.cs | 51 +++++++++---------- 5 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 Atomx.Core/Jos/SendVerificationCodeJob.cs diff --git a/Atomx.Core/Atomx.Core.csproj b/Atomx.Core/Atomx.Core.csproj index 63341ff..8e6eccd 100644 --- a/Atomx.Core/Atomx.Core.csproj +++ b/Atomx.Core/Atomx.Core.csproj @@ -12,6 +12,7 @@ + diff --git a/Atomx.Core/Jos/LocalizationJob.cs b/Atomx.Core/Jos/LocalizationJob.cs index 9b8d037..06dea1a 100644 --- a/Atomx.Core/Jos/LocalizationJob.cs +++ b/Atomx.Core/Jos/LocalizationJob.cs @@ -1,7 +1,5 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; +using Hangfire; +using Microsoft.Extensions.Logging; namespace Atomx.Core.Jos { @@ -9,7 +7,7 @@ namespace Atomx.Core.Jos /// /// 多语言本地化任务 /// - public partial class LocalizationJob + public class LocalizationJob { readonly ILogger _logger; public LocalizationJob(ILogger logger) @@ -17,10 +15,21 @@ namespace Atomx.Core.Jos _logger = logger; } - public void Execute() + /// + /// 如果任务失败,重试 3 次,超过后删除任务,60 秒内不允许并发执行 + /// + [AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Delete)] + [DisableConcurrentExecution(60)] + public void Execute(string path) { _logger.LogInformation("LocalizationJob executed at: {time}", DateTimeOffset.Now); // 在这里添加多语言本地化的具体任务逻辑 } + + public void ResetCache() + { + _logger.LogInformation("LocalizationJob ResetCache executed at: {time}", DateTimeOffset.Now); + // 在这里添加重置缓存的具体逻辑 + } } } diff --git a/Atomx.Core/Jos/SendVerificationCodeJob.cs b/Atomx.Core/Jos/SendVerificationCodeJob.cs new file mode 100644 index 0000000..9e79d5e --- /dev/null +++ b/Atomx.Core/Jos/SendVerificationCodeJob.cs @@ -0,0 +1,28 @@ +using Atomx.Data; +using Atomx.Data.CacheServices; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Atomx.Core.Jos +{ + public class SendVerificationCodeJob + { + readonly ILogger _logger; + readonly DataContext _dbContext; + readonly ICacheService _cacheService; + public SendVerificationCodeJob(ILogger logger, DataContext dataContext, ICacheService cacheService) + { + _logger = logger; + _dbContext = dataContext; + _cacheService = cacheService; + } + + public void Execute(string email, string code) + { + _logger.LogInformation("SendVerificationCodeJob executed at: {time}", DateTimeOffset.Now); + // 在这里添加发送验证码的具体任务逻辑 + } + } +} diff --git a/Atomx.Core/Services/BackgroundJobsService.cs b/Atomx.Core/Services/BackgroundJobsService.cs index e117c44..8d1d331 100644 --- a/Atomx.Core/Services/BackgroundJobsService.cs +++ b/Atomx.Core/Services/BackgroundJobsService.cs @@ -1,4 +1,6 @@ -using System; +using Hangfire; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.Text; @@ -6,9 +8,25 @@ namespace Atomx.Core.Jos { public partial interface IBackgroundJobsService { + string SendSMSVerificationCode(string phoneNumber, string code, TimeSpan validDuration); } public partial class BackgroundJobsService : IBackgroundJobsService { + readonly IBackgroundJobClient _backgroundJobClient; + readonly IRecurringJobManager _recurringJobManager; + readonly ILogger _logger; + public BackgroundJobsService(IBackgroundJobClient backgroundJobClient, IRecurringJobManager recurringJobManager, ILogger logger) + { + _backgroundJobClient = backgroundJobClient; + _recurringJobManager = recurringJobManager; + _logger = logger; + } + + public string SendSMSVerificationCode(string phoneNumber, string code, TimeSpan validDuration) + { + return string.Empty; + } + } } diff --git a/Atomx.Data/CacheServices/LocalizationCacheService.cs b/Atomx.Data/CacheServices/LocalizationCacheService.cs index 0df9214..cb0daa0 100644 --- a/Atomx.Data/CacheServices/LocalizationCacheService.cs +++ b/Atomx.Data/CacheServices/LocalizationCacheService.cs @@ -1,30 +1,29 @@ -//namespace Atomx.Data.CacheServices -//{ -// public partial interface ICacheService -// { -// Task SetLocalization(string id, LocalizationModel model); +namespace Atomx.Data.CacheServices +{ + public partial interface ICacheService + { + Task LoadLocale(string Culture); -// LocalizationModel GetLocalization(string id); -// } + } -// public partial class CacheService : ICacheService -// { -// public async Task SetLocalization(string id, LocalizationModel model) -// { -// var key = $"{CacheKeys.LocalizationPrefix}{id}"; -// await SetCacheAsync(key, model); -// } + public partial class CacheService : ICacheService + { + //public async Task SetLocalization(string id, LocalizationModel model) + //{ + // var key = $"{CacheKeys.LocalizationPrefix}{id}"; + // await SetCacheAsync(key, model); + //} -// public LocalizationModel GetLocalization(string id) -// { -// var key = $"{CacheKeys.LocalizationPrefix}{id}"; -// var cacheData = GetCache(key); -// if (cacheData == null) -// { -// return new LocalizationModel(); -// } -// return cacheData; -// } -// } + //public LocalizationModel GetLocalization(string id) + //{ + // var key = $"{CacheKeys.LocalizationPrefix}{id}"; + // var cacheData = GetCache(key); + // if (cacheData == null) + // { + // return new LocalizationModel(); + // } + // return cacheData; + //} + } -//} +}