diff --git a/CoreCms.Net.Core/Config/HangFireSetup.cs b/CoreCms.Net.Core/Config/HangFireSetup.cs index a051be49..1f81ef4c 100644 --- a/CoreCms.Net.Core/Config/HangFireSetup.cs +++ b/CoreCms.Net.Core/Config/HangFireSetup.cs @@ -20,6 +20,7 @@ using Hangfire.Redis; using Hangfire.SqlServer; using Microsoft.Extensions.DependencyInjection; using SqlSugar; +using StackExchange.Redis; namespace CoreCms.Net.Core.Config { @@ -28,6 +29,9 @@ namespace CoreCms.Net.Core.Config /// public static class HangFireSetup { + private static ConnectionMultiplexer _redis; + + public static void AddHangFireSetup(this IServiceCollection services) { if (services == null) throw new ArgumentNullException(nameof(services)); @@ -36,9 +40,13 @@ namespace CoreCms.Net.Core.Config var isEnabledRedis = AppSettingsConstVars.RedisUseTimedTask; 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,//后续列表中的最大可见后台作业,以防止它无限增长。 DeletedListSize = 500,//删除列表中的最大可见后台作业,以防止其无限增长。 InvisibilityTimeout = TimeSpan.FromMinutes(30), @@ -81,8 +89,7 @@ namespace CoreCms.Net.Core.Config options.ServerTimeout = TimeSpan.FromMinutes(4); options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点,一般任务可以配置默认时间,默认15秒 options.ShutdownTimeout = TimeSpan.FromMinutes(5); //超时时间 - //options.WorkerCount = Math.Max(Environment.ProcessorCount, 2); //工作线程数,当前允许的最大线程,默认20 - options.WorkerCount = 2; //工作线程数,当前允许的最大线程,默认20 + options.WorkerCount = Math.Max(Environment.ProcessorCount, 20); //工作线程数,当前允许的最大线程,默认20 }); } diff --git a/CoreCms.Net.Core/Config/SqlSugarSetup.cs b/CoreCms.Net.Core/Config/SqlSugarSetup.cs index 52a2ff5e..6128ba4f 100644 --- a/CoreCms.Net.Core/Config/SqlSugarSetup.cs +++ b/CoreCms.Net.Core/Config/SqlSugarSetup.cs @@ -46,11 +46,11 @@ namespace CoreCms.Net.Core.Config services.ConfigurationSugar(db => { db.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute; - db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices() - { - //判断是否开启redis设置二级缓存方式 - DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache() - }; + //db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices() + //{ + // //判断是否开启redis设置二级缓存方式 + // DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache() + //}; //执行SQL 错误事件,可监控sql(暂时屏蔽,需要可开启) //db.Aop.OnLogExecuting = (sql, p) => diff --git a/CoreCms.Net.Services/CoreCms.Net.Services.csproj b/CoreCms.Net.Services/CoreCms.Net.Services.csproj index d0e8fb95..4e47b103 100644 --- a/CoreCms.Net.Services/CoreCms.Net.Services.csproj +++ b/CoreCms.Net.Services/CoreCms.Net.Services.csproj @@ -7,7 +7,7 @@ - + diff --git a/CoreCms.Net.Task/HangfireDispose.cs b/CoreCms.Net.Task/HangfireDispose.cs index 983a5f3e..1f06d6a1 100644 --- a/CoreCms.Net.Task/HangfireDispose.cs +++ b/CoreCms.Net.Task/HangfireDispose.cs @@ -40,31 +40,29 @@ namespace CoreCms.Net.Task //这里呢就是需要触发的方法 "0/10 * * * * ? " 可以自行搜索cron表达式 代表循环的规律很简单 //CancelOrderJob代表你要触发的类 Execute代表你要触发的方法 - //自动取消订单任务 - RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Local); // 每5分钟取消一次订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Utc); // 每5分钟取消一次订单 //自动完成订单任务 - RecurringJob.AddOrUpdate(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单 //自动评价订单任务 - RecurringJob.AddOrUpdate(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单 //自动签收订单任务 - RecurringJob.AddOrUpdate(s => s.Execute(), Cron.Hourly, TimeZoneInfo.Local); // 每小时自动完成订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0 0/1 * * ? ", TimeZoneInfo.Utc); // 每小时自动完成订单 //催付款订单 - RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Local); // 每5分钟催付款订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/5 * * * ? ", TimeZoneInfo.Utc); // 每5分钟催付款订单 //拼团自动取消到期团(每分钟执行一次) - RecurringJob.AddOrUpdate(s => s.Execute(), Cron.Minutely, TimeZoneInfo.Local); // 每分钟取消一次订单 + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/2 * * * ? ", TimeZoneInfo.Utc); // 每分钟取消一次订单 //每天凌晨5点定期清理7天前操作日志 - RecurringJob.AddOrUpdate(s => s.Execute(), "0 0 5 * * ? ", TimeZoneInfo.Local); // 每天5点固定时间清理一次 - + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0 5 * * ? ", TimeZoneInfo.Utc); // 每天5点固定时间清理一次 //定时刷新获取微信AccessToken - RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/2 * * * ? ", TimeZoneInfo.Local); // 每2分钟刷新获取微信AccessToken + RecurringJob.AddOrUpdate(s => s.Execute(), "0 0/4 * * * ? ", TimeZoneInfo.Utc); // 每2分钟刷新获取微信AccessToken }