fix: 调整 Redis 配置与调度依赖

This commit is contained in:
2025-12-01 19:58:07 +08:00
parent 15fc000cfc
commit b692a94d3c
6 changed files with 62 additions and 71 deletions

View File

@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"Redis": "49.232.6.45:6379,password=MsuMshk112233,abortConnect=false"
},
"Database": {
"DataSources": {
"AppDatabase": {
@@ -30,7 +33,6 @@
}
}
},
"Redis": "49.232.6.45:6379,password=MsuMshk112233,abortConnect=false",
"Identity": {
"Jwt": {
"Issuer": "takeout-saas",

View File

@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"Redis": "49.232.6.45:6379,password=MsuMshk112233,abortConnect=false"
},
"Database": {
"DataSources": {
"AppDatabase": {
@@ -30,7 +33,6 @@
}
}
},
"Redis": "49.232.6.45:6379,password=MsuMshk112233,abortConnect=false",
"Identity": {
"Jwt": {
"Issuer": "takeout-saas",

View File

@@ -1,7 +1,7 @@
namespace TakeoutSaaS.Shared.Abstractions.Constants;
namespace TakeoutSaaS.Shared.Abstractions.Constants;
/// <summary>
/// 数据源名称常量,统一配置键与使用。
/// 数据源名称常量,统一配置键与使用说明
/// </summary>
public static class DatabaseConstants
{
@@ -16,7 +16,7 @@ public static class DatabaseConstants
public const string IdentityDataSource = "IdentityDatabase";
/// <summary>
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>DictionaryDatabase<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// 字典库(DictionaryDatabase)。
/// </summary>
public const string DictionaryDataSource = "DictionaryDatabase";
}

View File

@@ -42,10 +42,13 @@ public static class DatabaseServiceCollectionExtensions
string dataSourceName)
where TContext : DbContext
{
services.AddDbContext<TContext>((sp, options) =>
{
ConfigureDbContextOptions(sp, options, dataSourceName, DatabaseConnectionRole.Write);
});
services.AddDbContext<TContext>(
(sp, options) =>
{
ConfigureDbContextOptions(sp, options, dataSourceName, DatabaseConnectionRole.Write);
},
contextLifetime: ServiceLifetime.Scoped,
optionsLifetime: ServiceLifetime.Singleton);
services.AddDbContextFactory<TContext>((sp, options) =>
{

View File

@@ -1,4 +1,4 @@
using Hangfire;
using Hangfire;
using TakeoutSaaS.Module.Scheduler.Abstractions;
using TakeoutSaaS.Module.Scheduler.Jobs;
@@ -9,29 +9,12 @@ namespace TakeoutSaaS.Module.Scheduler.Services;
/// </summary>
public sealed class RecurringJobRegistrar : IRecurringJobRegistrar
{
private readonly OrderTimeoutJob _orderTimeoutJob;
private readonly CouponExpireJob _couponExpireJob;
private readonly LogCleanupJob _logCleanupJob;
/// <summary>
/// 初始化注册器。
/// </summary>
public RecurringJobRegistrar(
OrderTimeoutJob orderTimeoutJob,
CouponExpireJob couponExpireJob,
LogCleanupJob logCleanupJob)
{
_orderTimeoutJob = orderTimeoutJob;
_couponExpireJob = couponExpireJob;
_logCleanupJob = logCleanupJob;
}
/// <inheritdoc />
public Task RegisterAsync(CancellationToken cancellationToken = default)
{
RecurringJob.AddOrUpdate("orders.timeout-cancel", () => _orderTimeoutJob.ExecuteAsync(), "*/5 * * * *");
RecurringJob.AddOrUpdate("coupons.expire", () => _couponExpireJob.ExecuteAsync(), "0 */1 * * *");
RecurringJob.AddOrUpdate("logs.cleanup", () => _logCleanupJob.ExecuteAsync(), "0 3 * * *");
RecurringJob.AddOrUpdate<OrderTimeoutJob>("orders.timeout-cancel", job => job.ExecuteAsync(), "*/5 * * * *");
RecurringJob.AddOrUpdate<CouponExpireJob>("coupons.expire", job => job.ExecuteAsync(), "0 */1 * * *");
RecurringJob.AddOrUpdate<LogCleanupJob>("logs.cleanup", job => job.ExecuteAsync(), "0 3 * * *");
return Task.CompletedTask;
}
}