From 7837e78e5566795c72ac8549b8ebb9190e1fb6e0 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Wed, 24 Aug 2022 22:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86bug?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/Sample.MySql/Program.cs | 1 - .../Bootstrappers/IShardingBootstrapper.cs | 3 ++- src/ShardingCore/Bootstrappers/ShardingInitializer.cs | 2 -- .../Core/ServiceProviders/IShardingProvider.cs | 2 ++ .../Core/ServiceProviders/ShardingProvider.cs | 2 ++ src/ShardingCore/Jobs/Impls/JobEntry.cs | 11 +++++++++++ 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/samples/Sample.MySql/Program.cs b/samples/Sample.MySql/Program.cs index 76d867f4..b7b33031 100644 --- a/samples/Sample.MySql/Program.cs +++ b/samples/Sample.MySql/Program.cs @@ -13,7 +13,6 @@ namespace Sample.MySql { public static void Main(string[] args) { - var list = Enumerable.Range(1,3).Select(o=>(o%100).ToString().PadLeft(2,'0')).ToList(); CreateHostBuilder(args).Build().Run(); } diff --git a/src/ShardingCore/Bootstrappers/IShardingBootstrapper.cs b/src/ShardingCore/Bootstrappers/IShardingBootstrapper.cs index 5f1642d6..886cbb39 100644 --- a/src/ShardingCore/Bootstrappers/IShardingBootstrapper.cs +++ b/src/ShardingCore/Bootstrappers/IShardingBootstrapper.cs @@ -7,7 +7,8 @@ namespace ShardingCore.Bootstrappers { /// - /// 主要的分表初始化器,不再需要手动调用,IShardingRuntimeContext初始化的时候会调用 + /// 主要的分片初始化器,需要手动调用,如果你的分片路由存在定时执行的job譬如 + /// 系统默认的时间分片的情况下那么需要调用IShardingRuntimeContext初始化的时候会调用 /// public interface IShardingBootstrapper { diff --git a/src/ShardingCore/Bootstrappers/ShardingInitializer.cs b/src/ShardingCore/Bootstrappers/ShardingInitializer.cs index 4b995ba0..70b20903 100644 --- a/src/ShardingCore/Bootstrappers/ShardingInitializer.cs +++ b/src/ShardingCore/Bootstrappers/ShardingInitializer.cs @@ -41,7 +41,6 @@ namespace ShardingCore.Bootstrappers if (!_doOnlyOnce.IsUnDo()) return; _logger.LogDebug("sharding core starting......"); - _logger.LogDebug("sharding core initialize entity metadata......"); InitializeEntityMetadata(); _logger.LogDebug("sharding core initialize parallel table......"); @@ -63,7 +62,6 @@ namespace ShardingCore.Bootstrappers var entityMetadataInitializer =(IEntityMetadataInitializer)_shardingProvider.CreateInstance(entityMetadataInitializerType); entityMetadataInitializer.Initialize(); - } } diff --git a/src/ShardingCore/Core/ServiceProviders/IShardingProvider.cs b/src/ShardingCore/Core/ServiceProviders/IShardingProvider.cs index 54b6d35f..80528ba8 100644 --- a/src/ShardingCore/Core/ServiceProviders/IShardingProvider.cs +++ b/src/ShardingCore/Core/ServiceProviders/IShardingProvider.cs @@ -43,6 +43,8 @@ namespace ShardingCore.Core.ServiceProviders /// /// TService GetRequiredService(bool tryApplicationServiceProvider=true); + + IServiceProvider ApplicationServiceProvider { get; } IShardingScope CreateScope(); } diff --git a/src/ShardingCore/Core/ServiceProviders/ShardingProvider.cs b/src/ShardingCore/Core/ServiceProviders/ShardingProvider.cs index c5d57d52..63cb7a10 100644 --- a/src/ShardingCore/Core/ServiceProviders/ShardingProvider.cs +++ b/src/ShardingCore/Core/ServiceProviders/ShardingProvider.cs @@ -44,6 +44,8 @@ namespace ShardingCore.Core.ServiceProviders return (TService)GetRequiredService(typeof(TService),tryApplicationServiceProvider); } + public IServiceProvider ApplicationServiceProvider => _applicationServiceProvider; + public IShardingScope CreateScope() { return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider?.CreateScope()); diff --git a/src/ShardingCore/Jobs/Impls/JobEntry.cs b/src/ShardingCore/Jobs/Impls/JobEntry.cs index 2f072f84..d75c3162 100644 --- a/src/ShardingCore/Jobs/Impls/JobEntry.cs +++ b/src/ShardingCore/Jobs/Impls/JobEntry.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using System.Reflection; using System.Threading; +using ShardingCore.Exceptions; using ShardingCore.Jobs.Abstaractions; using ShardingCore.Jobs.Cron; @@ -20,6 +21,15 @@ namespace ShardingCore.Jobs.Impls JobInstance = job; JobName = job.JobName; JobCronExpressions = job.GetJobCronExpressions(); + if (JobCronExpressions == null) + { + throw new ArgumentException($" {nameof(JobCronExpressions)} is null"); + } + + if (JobCronExpressions.Any(o => o is null)) + { + throw new ArgumentException($"{nameof(JobCronExpressions)} has null element"); + } } /// /// 保证多线程只有一个清理操作 @@ -79,6 +89,7 @@ namespace ShardingCore.Jobs.Impls /// public void CalcNextUtcTime() { + this.NextUtcTime= JobCronExpressions.Select(cron => new CronExpression(cron).GetTimeAfter(DateTime.UtcNow)).Min(); } }