# 2022-01-24

### 1.3.4 开源社区版(会员专业版同步修改):
【修复】修复redis长期ping和info导致连接数无限增长,进而内存被耗尽的bug。
【修复】修复未填写redis链接或链接失败报错提示端口错误。
【优化】修改hangfire定时任务全部规则为cron表达式。
### 0.1.3 会员专业版:
同上。
This commit is contained in:
JianWeie
2022-01-25 01:44:29 +08:00
parent b5addd52cf
commit 5ac324812c
4 changed files with 25 additions and 20 deletions

View File

@@ -20,6 +20,7 @@ using Hangfire.Redis;
using Hangfire.SqlServer; using Hangfire.SqlServer;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SqlSugar; using SqlSugar;
using StackExchange.Redis;
namespace CoreCms.Net.Core.Config namespace CoreCms.Net.Core.Config
{ {
@@ -28,6 +29,9 @@ namespace CoreCms.Net.Core.Config
/// </summary> /// </summary>
public static class HangFireSetup public static class HangFireSetup
{ {
private static ConnectionMultiplexer _redis;
public static void AddHangFireSetup(this IServiceCollection services) public static void AddHangFireSetup(this IServiceCollection services)
{ {
if (services == null) throw new ArgumentNullException(nameof(services)); if (services == null) throw new ArgumentNullException(nameof(services));
@@ -36,9 +40,13 @@ namespace CoreCms.Net.Core.Config
var isEnabledRedis = AppSettingsConstVars.RedisUseTimedTask; var isEnabledRedis = AppSettingsConstVars.RedisUseTimedTask;
if (isEnabledRedis) if (isEnabledRedis)
{ {
services.AddHangfire(x => x.UseRedisStorage(AppSettingsConstVars.RedisConfigConnectionString, new RedisStorageOptions() var configuration = ConfigurationOptions.Parse(AppSettingsConstVars.RedisConfigConnectionString, true);
_redis = ConnectionMultiplexer.Connect(configuration);
var db = _redis.GetDatabase();
services.AddHangfire(x => x.UseRedisStorage(_redis, new RedisStorageOptions()
{ {
Db = 10, Db = db.Database, //建议根据
SucceededListSize = 500,//后续列表中的最大可见后台作业,以防止它无限增长。 SucceededListSize = 500,//后续列表中的最大可见后台作业,以防止它无限增长。
DeletedListSize = 500,//删除列表中的最大可见后台作业,以防止其无限增长。 DeletedListSize = 500,//删除列表中的最大可见后台作业,以防止其无限增长。
InvisibilityTimeout = TimeSpan.FromMinutes(30), InvisibilityTimeout = TimeSpan.FromMinutes(30),
@@ -81,8 +89,7 @@ namespace CoreCms.Net.Core.Config
options.ServerTimeout = TimeSpan.FromMinutes(4); options.ServerTimeout = TimeSpan.FromMinutes(4);
options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点一般任务可以配置默认时间默认15秒 options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点一般任务可以配置默认时间默认15秒
options.ShutdownTimeout = TimeSpan.FromMinutes(5); //超时时间 options.ShutdownTimeout = TimeSpan.FromMinutes(5); //超时时间
//options.WorkerCount = Math.Max(Environment.ProcessorCount, 2); //工作线程数当前允许的最大线程默认20 options.WorkerCount = Math.Max(Environment.ProcessorCount, 20); //工作线程数当前允许的最大线程默认20
options.WorkerCount = 2; //工作线程数当前允许的最大线程默认20
}); });
} }

View File

@@ -46,11 +46,11 @@ namespace CoreCms.Net.Core.Config
services.ConfigurationSugar(db => services.ConfigurationSugar(db =>
{ {
db.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute; db.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute;
db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices() //db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
{ //{
//判断是否开启redis设置二级缓存方式 // //判断是否开启redis设置二级缓存方式
DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache() // DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache()
}; //};
//执行SQL 错误事件可监控sql暂时屏蔽需要可开启 //执行SQL 错误事件可监控sql暂时屏蔽需要可开启
//db.Aop.OnLogExecuting = (sql, p) => //db.Aop.OnLogExecuting = (sql, p) =>

View File

@@ -7,7 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" /> <PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.0.8" /> <PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.0.8" />
<PackageReference Include="Flurl.Http" Version="3.2.0" /> <PackageReference Include="Flurl.Http" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />

View File

@@ -40,31 +40,29 @@ namespace CoreCms.Net.Task
//这里呢就是需要触发的方法 "0/10 * * * * ? " 可以自行搜索cron表达式 代表循环的规律很简单 //这里呢就是需要触发的方法 "0/10 * * * * ? " 可以自行搜索cron表达式 代表循环的规律很简单
//CancelOrderJob代表你要触发的类 Execute代表你要触发的方法 //CancelOrderJob代表你要触发的类 Execute代表你要触发的方法
//自动取消订单任务 //自动取消订单任务
RecurringJob.AddOrUpdate<AutoCancelOrderJob>(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Local); // 每5分钟取消一次订单 RecurringJob.AddOrUpdate<AutoCancelOrderJob>(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Utc); // 每5分钟取消一次订单
//自动完成订单任务 //自动完成订单任务
RecurringJob.AddOrUpdate<CompleteOrderJob>(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 RecurringJob.AddOrUpdate<CompleteOrderJob>(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单
//自动评价订单任务 //自动评价订单任务
RecurringJob.AddOrUpdate<EvaluateOrderJob>(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 RecurringJob.AddOrUpdate<EvaluateOrderJob>(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单
//自动签收订单任务 //自动签收订单任务
RecurringJob.AddOrUpdate<AutoSignOrderJob>(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 RecurringJob.AddOrUpdate<AutoSignOrderJob>(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单
//催付款订单 //催付款订单
RecurringJob.AddOrUpdate<RemindOrderPayJob>(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Local); // 每5分钟催付款订单 RecurringJob.AddOrUpdate<RemindOrderPayJob>(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Utc); // 每5分钟催付款订单
//拼团自动取消到期团(每分钟执行一次) //拼团自动取消到期团(每分钟执行一次)
RecurringJob.AddOrUpdate<AutoCanclePinTuanJob>(s => s.Execute(), Cron.Minutely, TimeZoneInfo.Local); // 每分钟取消一次订单 RecurringJob.AddOrUpdate<AutoCanclePinTuanJob>(s => s.Execute(), "0 0/2 * * * ? ", TimeZoneInfo.Utc); // 每分钟取消一次订单
//每天凌晨5点定期清理7天前操作日志 //每天凌晨5点定期清理7天前操作日志
RecurringJob.AddOrUpdate<RemoveOperationLogJob>(s => s.Execute(), "0 0 5 * * ? ", TimeZoneInfo.Local); // 每天5点固定时间清理一次 RecurringJob.AddOrUpdate<RemoveOperationLogJob>(s => s.Execute(), "0 0 5 * * ? ", TimeZoneInfo.Utc); // 每天5点固定时间清理一次
//定时刷新获取微信AccessToken //定时刷新获取微信AccessToken
RecurringJob.AddOrUpdate<RefreshWeChatAccessTokenJob>(s => s.Execute(), "0 0/2 * * * ? ", TimeZoneInfo.Local); // 每2分钟刷新获取微信AccessToken RecurringJob.AddOrUpdate<RefreshWeChatAccessTokenJob>(s => s.Execute(), "0 0/4 * * * ? ", TimeZoneInfo.Utc); // 每2分钟刷新获取微信AccessToken
} }