mar*_*rto 4 sitecore sitecore6
我需要在每天的确切时间运行sitecore计划任务.目前,任务按以下方式安排:
Schedule: 20100201T235900|20200201T235900|127|23:59:59
Last run: 2011 06 22 01:32:25
Run Code Online (Sandbox Code Playgroud)
该任务大约需要5分钟才能执行,因此"上次运行"会逐渐滑落并在稍后和之后运行.
我的主要想法是创建一个调用Web服务的Windows计划任务,并重置相关任务的上次运行时间.
还有另外一种方法吗?我错过了一些可以实现这一目标的配置属性吗?
我为此开发了自己的解决方案.
首先,将您的任务修改为每1分钟左右运行一次.它必须经常运行.您可以让任务在您喜欢的时候执行它的功能,而不是强制任务运行一次,然后等到第二天直到再次执行该功能:
在这个例子中,我强制我的任务在凌晨03:00到凌晨04:00之间运行一次:
public void Execute(Item[] itemArray, CommandItem commandItem, ScheduleItem scheduleItem)
{
if (!IsDue(scheduleItem))
return;
// DO MY STUFF!!
}
/// <summary>
/// Determines whether the specified schedule item is due to run.
/// </summary>
/// <remarks>
/// The scheduled item will only run between defined hours (usually at night) to ensure that the
/// email sending will not interfere with daily operations, and to ensure that the task is only run
/// once a day.
/// Make sure you configure the task to run at least double so often than the time span between
/// SendNotifyMailsAfter and SendNotifyMailsBefore
/// </remarks>
/// <param name="scheduleItem">The schedule item.</param>
/// <returns>
/// <c>true</c> if the specified schedule item is due; otherwise, <c>false</c>.
/// </returns>
private bool IsDue(ScheduleItem scheduleItem)
{
DateTime timeBegin;
DateTime timeEnd;
DateTime.TryParse("03:00:00", out timeBegin);
DateTime.TryParse("04:00:00", out timeEnd);
return (CheckTime(DateTime.Now, timeBegin, timeEnd) && !CheckTime(scheduleItem.LastRun, timeBegin, timeEnd));
}
private bool CheckTime(DateTime time, DateTime after, DateTime before)
{
return ((time >= after) && (time <= before));
}
Run Code Online (Sandbox Code Playgroud)
查看文章以获取更多详细信息:http: //briancaos.wordpress.com/2011/06/28/run-sitecore-scheduled-task-at-the-same-time-every-day/