Scheduled Task Start Time

I have been using ColdFusion since the 20th century and I thought I understood how it worked pretty well by now. I am not sure how this one slipped by me.

On one site, we have some aggregate reports that pull together fairly large amounts of data. When I first wrote the reports, they ran fine. As the site usage went up, however, these reports started taking too long to load. As a result, I had a friend of mine write some code to aggregate the data every night so that they would load quickly for the user. We tested the reports and everything worked great.

Recently, however, I noticed that the data seemed off. I couldn't find any problems, so I called my friend and he quickly saw (as I should have) that the nightly aggregation hadn't been run in a while.

He asked if the scheduled task was working. I said I knew that it was because I only have one scheduled task and the same page fires off a weekly email that has been working. Clearly, however, the code had not been executing.

I looked at the page being called by the scheduled task and found this:

<cfif Hour(now()) GTE 3 AND Hour(now()) LT 4>
<!--- call to reporting CFC here --->
</cfif>

Now I believed that this would have to run for an hourly task. I checked the task in the ColdFusion Administrator and verified that task was hourly. It was, so I could see no reason for this not to work.

Desperate, I changed the "LT" to an "LTE" and checked back the next day - still nothing.

Then the answer (and my misunderstanding) became clear:

The start time for the task was "11:00 AM". My understanding had always been that the start time just meant that the first time the task ran, it ran on that time on the start date, and then every hour (24 hours a day) from there on. This seems not to have been the case.

I changed the start time to "1:00 AM" and found the next day that the report had run.

I believe that this was working before we upgraded to CF8, so this may be a change in CF8. I have not had time to test that hypothesis, however.

So, always make sure that your start time precedes any task that you want to run.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
It was always my understanding that the start time applied to every iteration of the task (i.e. if hourly and start time of 11a, it would run from 11a to the end time time (or the end of the day, if no end time was specified) every day. If weekly task and start time of 11a, it would run once a week at 11a). I just confirmed this in the logs for our CF7 servers, and our hourly tasks that are scheduled to run from 11a-4p run at 11, 12, 1, 2, 3, and 4. Is it possible that the start time for the task was changed at some point?
# Posted By Rich Rein | 1/24/08 10:39 AM
Rich,

That certainly appears to be the case - I'm not sure how I got myself all mixed up about it.
# Posted By Steve Bryant | 1/24/08 10:44 AM
So this would mean that your task would only execute if the 'HOUR' was currently 3 right - (greater than or equal to 3 and less than 4).

So your Scheduler is set to 'hourly', then this should only execute on the 3rd hour - assuming 1x a day then right? (as a time of 3 pm returns 15 as the hour)

So yes, I could see, setting up a Scheduler for 11 am would not work - even though, the next day - hourly, a person would think that the task would roll to the next hour in the morning etc.

The key here is to look at the scheduler log - and look for the 'Rescheduling for' value - as when a scheduled event ends - it should setup the next schedule for you. (make sure you log scheduled tasks etc - cfadmin Debugging and Settings - Logging Settings Enable logging for scheduled tasks)

I'm currently in a thread on the yahoo 'coldferusion' group about a scheduled task issue I'm seeing and is repeatable regarding long running threads, if interested http://tech.groups.yahoo.com/group/colderfusion.
# Posted By Kevin Penny | 1/28/08 12:58 PM
Kevin,

That is correct. Certainly, I could have just set up a daily scheduled task to run at 3:00 AM for the same effect.

I avoided doing so only because I have one file on this site through which I manage all scheduled tasks - keeps me from having to clutter up the admin with a bunch of scheduled tasks some of which have rather complicated logic for determining the timing.

Good advice about looking at the scheduler logs - I certainly should have done that.
# Posted By Steve Bryant | 1/29/08 2:00 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.