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" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access