The other day I found myself scheduling a task which would send out financial reports to users on a daily basis. The task really didn't need to run on the weekends, but there's no way to indicate that in the CF Administrator-- the scheduling form it gives you either lets you run at a specific date and time; daily/weekly/monthly at a specific time; or daily at a specified interval. There's nothing that will let you run a task only on certain days of the week.
Luckily, that's easy enough to control within your scheduled task itself. All you have to do is check to see what day of the week it is and abort page processing if this day is one on which you don't want to run the task. If you check the calling user agent, you can even give yourself the flexibility to call the task to test it on the days you don't want it to normally run. Sample code is below:
<!--- If this page is being called as a scheduled task and the current day is Saturday or Sunday --->
<cfif CGI.HTTP_USER_AGENT eq 'CFSCHEDULE' and ListFind('1,7', DayOfWeek(Now()))>
<!--- Abort the page with a message --->
This page doesn't run on weekends.<cfabort>
</cfif>

Comments (1)
September 26, 2007
14:24PM | #
Heh -- learn something new every day -- and nevermind the date stuff. I didn't realize the scheduler did an override of HTTP_USER_AGENT -- that's pretty handy.