移除补偿cron表达式
This commit is contained in:
parent
dfc3984ce2
commit
ace2d0cb6c
|
@ -10,6 +10,7 @@ using ShardingCore;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using ShardingCore.Helpers;
|
||||
using ShardingCore.Sharding.ReadWriteConfigurations;
|
||||
|
||||
namespace Sample.SqlServer
|
||||
|
|
|
@ -91,18 +91,11 @@ namespace ShardingCore.VirtualRoutes.Abstractions
|
|||
/// </summary>
|
||||
public virtual int IncrementMinutes => 10;
|
||||
|
||||
public string[] GetJobCronExpressions()
|
||||
public virtual string[] GetJobCronExpressions()
|
||||
{
|
||||
var cronExpressions = GetCronExpressions();
|
||||
var compensateCronExpressions = GetCompensateCronExpressions();
|
||||
return cronExpressions.Concat(compensateCronExpressions).Distinct().ToArray();
|
||||
return GetCronExpressions();
|
||||
}
|
||||
/// <summary>
|
||||
/// 补偿cron防止提前创建后没有添加tail到内存中从而无法识别
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract string[] GetCompensateCronExpressions();
|
||||
/// <summary>
|
||||
/// 重写改方法后请一起重写IncrementMinutes值,比如你按月分表但是你设置cron表达式为月中的时候建表,
|
||||
/// 那么会在月中的时候 <code>DateTime.Now.AddMinutes(IncrementMinutes);</code>来获取tail会导致还是当月的所以不会建表
|
||||
/// </summary>
|
||||
|
|
|
@ -2,6 +2,7 @@ using ShardingCore.Core.VirtualRoutes;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Days
|
||||
{
|
||||
|
@ -11,13 +12,16 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
* @Date: Wednesday, 27 January 2021 08:41:05
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
public abstract class AbstractSimpleShardingDayKeyDateTimeVirtualTableRoute<TEntity>:AbstractShardingTimeKeyDateTimeVirtualTableRoute<TEntity> where TEntity:class
|
||||
public abstract class
|
||||
AbstractSimpleShardingDayKeyDateTimeVirtualTableRoute<TEntity> :
|
||||
AbstractShardingTimeKeyDateTimeVirtualTableRoute<TEntity> where TEntity : class
|
||||
{
|
||||
/// <summary>
|
||||
/// begin time use fixed time eg.new DateTime(20xx,xx,xx)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract DateTime GetBeginTime();
|
||||
|
||||
/// <summary>
|
||||
/// 这个方法会在程序启动的时候被调用,后续整个生命周期将不会被调用,仅用来告诉框架启动的时候有多少张TEntity对象的后缀表,
|
||||
/// 然后会在启动的时候添加到 <see cref="IVirtualTable{TEntity}.AddPhysicTable(IPhysicTable physicTable)"/>
|
||||
|
@ -27,7 +31,7 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
{
|
||||
var beginTime = GetBeginTime().Date;
|
||||
|
||||
var tails=new List<string>();
|
||||
var tails = new List<string>();
|
||||
//提前创建表
|
||||
var nowTimeStamp = DateTime.Now.Date;
|
||||
if (beginTime > nowTimeStamp)
|
||||
|
@ -39,8 +43,10 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
tails.Add(tail);
|
||||
currentTimeStamp = currentTimeStamp.AddDays(1);
|
||||
}
|
||||
|
||||
return tails;
|
||||
}
|
||||
|
||||
protected override string TimeFormatToTail(DateTime time)
|
||||
{
|
||||
return $"{time:yyyyMMdd}";
|
||||
|
@ -53,17 +59,17 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
{
|
||||
case ShardingOperatorEnum.GreaterThan:
|
||||
case ShardingOperatorEnum.GreaterThanOrEqual:
|
||||
return tail =>String.Compare(tail, t, StringComparison.Ordinal) >= 0;
|
||||
return tail => String.Compare(tail, t, StringComparison.Ordinal) >= 0;
|
||||
case ShardingOperatorEnum.LessThan:
|
||||
{
|
||||
var shardingKeyDate = shardingKey.Date;
|
||||
//处于临界值 o=>o.time < [2021-01-01 00:00:00] 尾巴20210101不应该被返回
|
||||
if (shardingKeyDate == shardingKey)
|
||||
return tail =>String.Compare(tail, t, StringComparison.Ordinal) < 0;
|
||||
return tail =>String.Compare(tail, t, StringComparison.Ordinal) <= 0;
|
||||
return tail => String.Compare(tail, t, StringComparison.Ordinal) < 0;
|
||||
return tail => String.Compare(tail, t, StringComparison.Ordinal) <= 0;
|
||||
}
|
||||
case ShardingOperatorEnum.LessThanOrEqual:
|
||||
return tail =>String.Compare(tail, t, StringComparison.Ordinal) <= 0;
|
||||
return tail => String.Compare(tail, t, StringComparison.Ordinal) <= 0;
|
||||
case ShardingOperatorEnum.Equal: return tail => tail == t;
|
||||
default:
|
||||
{
|
||||
|
@ -85,10 +91,10 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
};
|
||||
}
|
||||
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 * * ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new[] { "0 0 0 * * ?" }).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Days
|
||||
|
@ -80,9 +81,11 @@ namespace ShardingCore.VirtualRoutes.Days
|
|||
"0 1 0 * * ?",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 * * ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 * * ?" }).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Months
|
||||
|
@ -76,9 +77,10 @@ namespace ShardingCore.VirtualRoutes.Months
|
|||
"0 1 0 1 * ?",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 1 * ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 1 * ?"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Months
|
||||
|
@ -79,9 +80,10 @@ namespace ShardingCore.VirtualRoutes.Months
|
|||
"0 1 0 1 * ?",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 1 * ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 1 * ?"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Weeks
|
||||
|
@ -78,9 +79,10 @@ namespace ShardingCore.VirtualRoutes.Weeks
|
|||
"0 1 0 ? * 2",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 ? * 2" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 ? * 2"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Weeks
|
||||
{
|
||||
|
@ -81,9 +82,10 @@ namespace ShardingCore.VirtualRoutes.Weeks
|
|||
"0 1 0 ? * 2",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 ? * 2" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 ? * 2"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using ShardingCore.Core.VirtualRoutes;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Years
|
||||
|
@ -78,9 +79,10 @@ namespace ShardingCore.VirtualRoutes.Years
|
|||
"0 1 0 1 1 ?",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 1 1 ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 1 1 ?"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using ShardingCore.Helpers;
|
|||
using ShardingCore.VirtualRoutes.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ShardingCore.VirtualRoutes.Years
|
||||
|
@ -102,9 +103,10 @@ namespace ShardingCore.VirtualRoutes.Years
|
|||
"0 1 0 1 1 ?",
|
||||
};
|
||||
}
|
||||
public override string[] GetCompensateCronExpressions()
|
||||
public override string[] GetJobCronExpressions()
|
||||
{
|
||||
return new[] { "0 0 0 1 1 ?" };
|
||||
var crons = base.GetJobCronExpressions().Concat(new []{"0 0 0 1 1 ?"}).Distinct().ToArray();
|
||||
return crons;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue