添加重写cron表达式也需要重写 IncrementMinutes发布x.3.1.82
This commit is contained in:
parent
352bec4e93
commit
fbba530965
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.3.1.81
|
||||
set EFCORE3=3.3.1.81
|
||||
set EFCORE5=5.3.1.81
|
||||
set EFCORE6=6.3.1.81
|
||||
set EFCORE2=2.3.1.82
|
||||
set EFCORE3=3.3.1.82
|
||||
set EFCORE5=5.3.1.82
|
||||
set EFCORE6=6.3.1.82
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
|
|||
using Sample.SqlServerShardingDataSource.VirtualRoutes;
|
||||
using ShardingCore;
|
||||
using System.Collections.Generic;
|
||||
using ShardingCore.TableExists;
|
||||
|
||||
namespace Sample.SqlServerShardingDataSource
|
||||
{
|
||||
|
@ -38,7 +39,7 @@ namespace Sample.SqlServerShardingDataSource
|
|||
op.AutoTrackEntity = true;
|
||||
//Èç¹ûÄúʹÓÃcode-first½¨ÒéÑ¡Ôñfalse
|
||||
op.CreateShardingTableOnStart = true;
|
||||
//如果您使用code-first建议修改为fsle
|
||||
//如果您使用code-first建议修改为false
|
||||
op.EnsureCreatedWithOutShardingTable = true;
|
||||
}).AddShardingTransaction((connection, builder) =>
|
||||
{
|
||||
|
@ -63,7 +64,8 @@ namespace Sample.SqlServerShardingDataSource
|
|||
{
|
||||
op.AddShardingDatabaseRoute<SysUserVirtualDataSourceRoute>();
|
||||
op.AddShardingDatabaseRoute<OrderVirtualDataSourceRoute>();
|
||||
}).End();
|
||||
}).AddTableEnsureManager(sp=>new SqlServerTableEnsureManager<MyDbContext>())
|
||||
.End();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
|
@ -53,12 +53,17 @@ namespace ShardingCore.DynamicDataSources
|
|||
_logger = logger;
|
||||
}
|
||||
public void InitConfigure(string dataSourceName, string connectionString)
|
||||
{
|
||||
InitConfigure(dataSourceName,connectionString, _shardingConfigOption.EnsureCreatedWithOutShardingTable);
|
||||
}
|
||||
|
||||
public void InitConfigure(string dataSourceName, string connectionString, bool createDatabase)
|
||||
{
|
||||
using (var serviceScope = ShardingContainer.ServiceProvider.CreateScope())
|
||||
{
|
||||
_virtualDataSource.AddPhysicDataSource(new DefaultPhysicDataSource(dataSourceName, connectionString, false));
|
||||
using var context = serviceScope.ServiceProvider.GetService<TShardingDbContext>();
|
||||
if (_shardingConfigOption.EnsureCreatedWithOutShardingTable)
|
||||
if (createDatabase)
|
||||
EnsureCreated(context, dataSourceName);
|
||||
var tableEnsureManager = ShardingContainer.GetService<ITableEnsureManager<TShardingDbContext>>();
|
||||
//获取数据库存在的所有的表
|
||||
|
@ -99,6 +104,7 @@ namespace ShardingCore.DynamicDataSources
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDataTable(string dataSourceName, IVirtualTable virtualTable, ISet<string> existTables)
|
||||
{
|
||||
var entityMetadata = virtualTable.EntityMetadata;
|
||||
|
|
|
@ -11,5 +11,6 @@ namespace ShardingCore.DynamicDataSources
|
|||
public interface IDataSourceInitializer<TShardingDbContext> where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
void InitConfigure(string dataSourceName, string connectionString);
|
||||
void InitConfigure(string dataSourceName, string connectionString,bool createDatabase);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,15 @@ namespace ShardingCore.VirtualRoutes.Abstractions
|
|||
/// 显示错误日志
|
||||
/// </summary>
|
||||
public virtual bool DoLogError => false;
|
||||
|
||||
/// <summary>
|
||||
/// 默认会在设置时间后10分钟获取tail
|
||||
/// </summary>
|
||||
public virtual int IncrementMinutes => 10;
|
||||
/// <summary>
|
||||
/// 重写改方法后请一起重写IncrementMinutes值,比如你按月分表但是你设置cron表达式为月中的时候建表,
|
||||
/// 那么会在月中的时候 <code>DateTime.Now.AddMinutes(IncrementMinutes);</code>来获取tail会导致还是当月的所以不会建表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract string[] GetCronExpressions();
|
||||
public Task ExecuteAsync()
|
||||
{
|
||||
|
@ -58,7 +66,7 @@ namespace ShardingCore.VirtualRoutes.Abstractions
|
|||
var entityMetadataManager = (IEntityMetadataManager)ShardingContainer.GetService(typeof(IEntityMetadataManager<>).GetGenericType0(EntityMetadata.ShardingDbContextType));
|
||||
var virtualDataSource = (IVirtualDataSource)ShardingContainer.GetService(typeof(IVirtualDataSource<>).GetGenericType0(EntityMetadata.ShardingDbContextType));
|
||||
var tableCreator = (IShardingTableCreator)ShardingContainer.GetService(typeof(IShardingTableCreator<>).GetGenericType0(EntityMetadata.ShardingDbContextType));
|
||||
var now = DateTime.Now.AddMinutes(10);
|
||||
var now = DateTime.Now.AddMinutes(IncrementMinutes);
|
||||
var tail = virtualTable.GetVirtualRoute().ShardingKeyToTail(now);
|
||||
ISet<string> dataSources = new HashSet<string>();
|
||||
if (entityMetadataManager.IsShardingDataSource(typeof(TEntity)))
|
||||
|
|
Loading…
Reference in New Issue