Scheduler in Umbraco

Umbraco has a built in scheduler function. I did not find much documentation about it so here’s some notes of how to use the scheduler for different kind of tasks at certain times.

In the file /config/umbracoSettings.config there’s a commented setting that if active runs every x seconds:

<!-- add tasks that should be called with an interval (seconds) --></div>
<div id="_mcePaste"><!--    <task log="true" alias="test60" interval="60" url="http://localhost/umbraco/test.aspx"/>-->

If you uncomment it and set a real url to your site Umbraco will open that address at the specified interval.

<task log="true" alias="test60" interval="60" url="http://www.mysite.com/runscheduler.aspx"/>

Now if you add a page at that address that contains a macro that macro will run obviously. But how to control when it will run? Say that you need something to run each day at 8:00, or once a week or something like that. Here’s a Xslt- that sends an email at certain times:

<xsl:template match="/">
<xsl:variable name="sendFromAddress" select="'website@mycompany.com'"/>
<xsl:variable name="sendToAddress" select="'admin@mycompany.com'"/>

<!--
This sample is made for scheduling each 60 seconds
-->
<xsl:variable name="minuteInHour" select="Exslt.ExsltDatesAndTimes:minuteinhour()"/>

<!--
If the scheduler runs every 10 minutes (600) instead change to this (return 0, 10, 20 .. 50)
<xsl:variable name="minuteInHour" select="round(Exslt.ExsltDatesAndTimes:minuteinhour() div 10)*10"/>
-->

<xsl:variable name="hourInDay" select="Exslt.ExsltDatesAndTimes:hourinday()"/>
<xsl:variable name="dayInWeek" select="Exslt.ExsltDatesAndTimes:dayinweek()"/>

<!--
Three sample triggers:
'Run once every hour at hh:00', 'Run once a day at 8:00' and 'Run each first 5 days of the week, at 8:00'
-->

<xsl:if test="$minuteInHour=0">
<xsl:value-of select="umbraco.library:SendMail($sendFromAddress, $sendToAddress, 'Triggered by site schedule', 'Run once every hour at hh:00', false())"/>
</xsl:if>

<xsl:if test="$hourInDay=8 and $minuteInHour=0">
<xsl:value-of select="umbraco.library:SendMail($sendFromAddress, $sendToAddress, 'Triggered by site schedule', 'Run once a day at 8:00', false())"/>
</xsl:if>

<xsl:if test="$dayInWeek&lt;6 and $hourInDay=8 and $minuteInHour=0">
<xsl:value-of select="umbraco.library:SendMail($sendFromAddress, $sendToAddress, 'Triggered by site schedule', 'Run each first 5 days of the week, at 8:00', false())"/>
</xsl:if>
</xsl:template>
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s