6

I have looked at the documentation but I can't find anything that either confirms or denies that it's possible to run an agent every 48 or 72 hours for example.

From what I can see the longest interval for any out of the box agent is 24hrs.

12

Definitely - all Sitecore does when reading in your agents is parse the interval as a TimeSpan via the following line of code, from the Sitecore.Tasks.Scheduler.ReadAgents method:

TimeSpan timeSpan = DateUtil.ParseTimeSpan(XmlUtil.GetAttribute("interval", configNode), TimeSpan.FromSeconds(0.0), CultureInfo.InvariantCulture);

The Sitecore.DateUtil method that is called to actually parse the interval is as follows:

public static TimeSpan ParseTimeSpan(string time, TimeSpan defaultValue, CultureInfo cultureInfo)
{
  Assert.ArgumentNotNull((object) cultureInfo, "cultureInfo");
  return DateUtil.ParseTimeSpan(time, cultureInfo) ?? defaultValue;
}

Sitecore's DateUtil.ParseTimeSpan method includes a lot of custom parsing logic that adds support for custom syntaxes. All of the following are valid format strings:

"00:00:24"   -> 24 seconds
"00:24:00"   -> 24 minutes
"24:00:00"   -> 24 hours
"1.00:00:00" -> 1 day (24 hours)
"1.24:00:00" -> 1 day and 24 hours (2 days or 48 hours)

Word of Caution

Before you set such a long interval for your agents, have a look at the section "The Problem with Agents" in this post. It explains a major pitfall of scheduler agents that you should be aware of.

To summarize, the because agents cannot be attached to a particular time of day, the clock resets whenever the application restarts, meaning that as the duration of the interval increases so too does the likelihood that the agent will not run at all within the defined duration of the interval. This means that if your application restarts every 1-47 hours (due to a crash, app pool recycle, etc.) then your agent will never run at all.

If you are looking to set an agent to run at a longer interval, my first recommendation is that you assess to make sure that nothing will break if your agent doesn't run, that an agent really is the right tool for you to use and that you have logging set up so that you can always tell if and when your agent ran.

  • 1
    The answer is yes and Zachary did a great job explaining it above. I also recommend looking at the SItecron module which gives you much more granular control on when your scheduled job runs. marketplace.sitecore.net/Modules/S/Sitecron – Chirag Patel Sep 12 '17 at 16:01
  • Thanks for the explanation Zachary. I was aware of the app pool recycling issue and that is definitely a problem and worth calling out to anyone also considering long intervals between agents running. It's good to know it's possible to run agents for longer than 24hrs. From my tests though (with no app pool recycles) my agent isn't running if set to more than 24hrs. So I have already re-written it to use Sitecron (thanks for calling this out too though Chirag). – Adam Seabridge Sep 12 '17 at 16:10
  • There is also this Quartz cron as an option but I went with Sitecron: sitecore.badalkotecha.com/2016/11/…. Glad to get this clarified though anyway. – Adam Seabridge Sep 12 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.