Scheduling Tasks with cfschedule

Besides being able to schedule tasks with the ColdFusion Administrator, you can use the cfschedule tag to do it programmatically. With the cfschedule tag, you can add, update, delete, and run scheduled tasks. Scheduling tasks programmatically lets you add a whole new level of functionality to your applications. For example, you can create a reporting application that allows users to have automatic email delivery of their reports on a scheduled basis. With the cfschedule tag, it is easy to set things up so that your application automatically schedules a task for each user. And each task can automatically generate a report and email it to the user at a chosen interval.

The attributes used by the cfschedule tag roughly coincide with the form fields from the Add/Edit Scheduled Task page in the ColdFusion Administrator, as you can see in Appendix A.

Adding Tasks

Adding a task to the Scheduler using cfschedule is a lot like adding a task via the ColdFusion Administrator. The information you enter in the ColdFusion Administrator is the same information you specify for the cfschedule tag attributes. For example, to schedule a task called MyTask that calls the template located at http://www.example.com/myscript.cfm once a day at 1:30 p.m., you can use the following code:

<cfschedule action="Update" task="MyTask" operation="HTTPRequest" URL="http://www.example.com/myscript.cfm" startdate="#DateFormat(Now( ),'mm/dd/yyyy')#" starttime="13:30:00" interval="Daily" ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.