修复部分bug增加更多功能

This commit is contained in:
xuejiaming 2022-08-24 22:03:31 +08:00
parent 36d8709efe
commit 7837e78e55
6 changed files with 17 additions and 4 deletions

View File

@ -13,7 +13,6 @@ namespace Sample.MySql
{ {
public static void Main(string[] args) 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(); CreateHostBuilder(args).Build().Run();
} }

View File

@ -7,7 +7,8 @@
namespace ShardingCore.Bootstrappers namespace ShardingCore.Bootstrappers
{ {
/// <summary> /// <summary>
/// 主要的分表初始化器,不再需要手动调用,<code>IShardingRuntimeContext初始化的时候会调用</code> /// 主要的分片初始化器,需要手动调用,如果你的分片路由存在定时执行的job譬如
/// 系统默认的时间分片的情况下那么需要调用<code>IShardingRuntimeContext初始化的时候会调用</code>
/// </summary> /// </summary>
public interface IShardingBootstrapper public interface IShardingBootstrapper
{ {

View File

@ -41,7 +41,6 @@ namespace ShardingCore.Bootstrappers
if (!_doOnlyOnce.IsUnDo()) if (!_doOnlyOnce.IsUnDo())
return; return;
_logger.LogDebug("sharding core starting......"); _logger.LogDebug("sharding core starting......");
_logger.LogDebug("sharding core initialize entity metadata......"); _logger.LogDebug("sharding core initialize entity metadata......");
InitializeEntityMetadata(); InitializeEntityMetadata();
_logger.LogDebug("sharding core initialize parallel table......"); _logger.LogDebug("sharding core initialize parallel table......");
@ -63,7 +62,6 @@ namespace ShardingCore.Bootstrappers
var entityMetadataInitializer =(IEntityMetadataInitializer)_shardingProvider.CreateInstance(entityMetadataInitializerType); var entityMetadataInitializer =(IEntityMetadataInitializer)_shardingProvider.CreateInstance(entityMetadataInitializerType);
entityMetadataInitializer.Initialize(); entityMetadataInitializer.Initialize();
} }
} }

View File

@ -44,6 +44,8 @@ namespace ShardingCore.Core.ServiceProviders
/// <returns></returns> /// <returns></returns>
TService GetRequiredService<TService>(bool tryApplicationServiceProvider=true); TService GetRequiredService<TService>(bool tryApplicationServiceProvider=true);
IServiceProvider ApplicationServiceProvider { get; }
IShardingScope CreateScope(); IShardingScope CreateScope();
} }
} }

View File

@ -44,6 +44,8 @@ namespace ShardingCore.Core.ServiceProviders
return (TService)GetRequiredService(typeof(TService),tryApplicationServiceProvider); return (TService)GetRequiredService(typeof(TService),tryApplicationServiceProvider);
} }
public IServiceProvider ApplicationServiceProvider => _applicationServiceProvider;
public IShardingScope CreateScope() public IShardingScope CreateScope()
{ {
return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider?.CreateScope()); return new ShardingScope(_internalServiceProvider.CreateScope(), _applicationServiceProvider?.CreateScope());

View File

@ -2,6 +2,7 @@ using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using ShardingCore.Exceptions;
using ShardingCore.Jobs.Abstaractions; using ShardingCore.Jobs.Abstaractions;
using ShardingCore.Jobs.Cron; using ShardingCore.Jobs.Cron;
@ -20,6 +21,15 @@ namespace ShardingCore.Jobs.Impls
JobInstance = job; JobInstance = job;
JobName = job.JobName; JobName = job.JobName;
JobCronExpressions = job.GetJobCronExpressions(); 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");
}
} }
/// <summary> /// <summary>
/// 保证多线程只有一个清理操作 /// 保证多线程只有一个清理操作
@ -79,6 +89,7 @@ namespace ShardingCore.Jobs.Impls
/// </summary> /// </summary>
public void CalcNextUtcTime() public void CalcNextUtcTime()
{ {
this.NextUtcTime= JobCronExpressions.Select(cron => new CronExpression(cron).GetTimeAfter(DateTime.UtcNow)).Min(); this.NextUtcTime= JobCronExpressions.Select(cron => new CronExpression(cron).GetTimeAfter(DateTime.UtcNow)).Min();
} }
} }