每天在同一时间运行sitecore计划任务

时间:2011-06-23 14:57:56

标签: sitecore sitecore6

我需要在每天的确切时间运行sitecore计划任务。 目前,任务按以下方式安排:

Schedule: 20100201T235900|20200201T235900|127|23:59:59
Last run: 2011 06 22 01:32:25

该任务大约需要5分钟才能执行,因此'上次运行'会逐渐滑落,稍后再运行。

我的主要想法是创建一个调用Web服务的Windows计划任务,并重置相关任务的上次运行时间。

还有其他方法吗?我错过了一些可以更容易实现这一目标的配置属性吗?

3 个答案:

答案 0 :(得分:5)

我为此开发了自己的解决方案。

首先,将您的任务修改为每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));
}

查看文章以获取更多详细信息: http://briancaos.wordpress.com/2011/06/28/run-sitecore-scheduled-task-at-the-same-time-every-day/

答案 1 :(得分:2)

尝试启用异步执行,即使任务仍在运行,也应立即更新“上次运行”时间。另外,对于你的最后一个参数,你可以使用“1.00:00:00”代替“23:59:59”来让它每1天执行一次。

编辑:另一种可能性是DatabaseAgent的频率。它多久运行一次?如果它只是每10分钟运行一次,默认情况下,则检查不一定会在您希望的那一刻发生。只有当它醒来时尝试将间隔更改为1分钟甚至更短。

  <!-- Agent to process schedules embedded as items in a database -->
  <agent type="Sitecore.Tasks.DatabaseAgent" method="Run" interval="00:10:00">
    <param desc="database">master</param>
    <param desc="schedule root">/sitecore/system/tasks/schedules</param>
    <LogActivity>true</LogActivity>
  </agent>

答案 2 :(得分:0)

很难让每天在同一时间运行某些东西。大部分时间都是因为Sitecore根据刻度而不是时间来考虑时间。因此,应用程序回收之间的时间就是滴答声。

我们之前通过实施Windows计划任务完成了同样的事情。我们的任务调用wget(Windows版本),wget向我们网站上的特殊页面发出请求。我们对该页面有IP限制,因此只有服务器可以通过wget通过请求来访问它。我们从未遇到任何问题,如果我们需要手动运行代码,我们要么从服务器点击页面,要么只登录服务器并在那时运行计划任务。

相关问题