ColdFusion Scheduled Tasks
ColdFusion Scheduled Tasks enable you to schedule any ColdFusion template to run at any time. In fact, it doesn't even have to be a ColdFusion template - you can run any file, as long as its accessible via URL.
ColdFusion Scheduled Tasks makes it easy to perform regular tasks, such as sending email newsletters, refresh Verity collections etc.
ColdFusion Scheduled Tasks can be configured either programatically (using the CFSCHEDULE tag)or via the ColdFusion Administrator.
Which method you use is up to you, but this choice will be made easier if you don't have access to the ColdFusion Administrator! Mind you, the CFSCHEDULE tag (and many others) can be disabled via the ColdFusion Administrator (Sandbox security page) so you may need to check that your server administrator hasn't disabled this tag.
Configuring ColdFusion Scheduled Tasks via the ColdFusion AdministratorYou can either use this option, or the CFSCHEDULE tag (below) to configure scheduled tasks with ColdFusion.
- Log in to the ColdFusion Administrator
- Click Scheduled Tasks
- Click Schedule New Task
- Enter a task name, choose a start date or frequency, enter the URL of the template the scheduler will run. All other options are optional but you may need them depending on what your task does. For example, if you think the template will run for a long time, you should indicate a timeout which will override the default timeout. This will prevent the template from timing out before it gets a chance to complete.
- Click Submit
Your scheduled task will now run at the scheduled time. To test your task, click the Run Scheduled Task icon.
Configuring ColdFusion Scheduled Tasks using the CFSCHEDULE tag
- Create a ColdFusion template
- Type your
CFSCHEDULEcode using the
- Save your template inside your ColdFusion application
- Run the template (i.e. open it in your browser)
Running the template will either update the ColdFusion scheduled task, or create it if it doesn't already exist. You will now see this listed in the ColdFusion Administrator under Scheduled Tasks.
<cfschedule action = "update" task = "taskname" operation = "HTTPRequest" file = "filename" path = "path_to_file" startDate = "date" startTime = "time" url = "URL" port = "port_number" publish = "Yes" or "No" endDate = "date" endTime = "time" interval = "seconds" requestTimeOut = "seconds" username = "username" password = "password" proxyServer = "hostname" proxyPort = "port_number" proxyUser = "username" proxyPassword = "password" resolveURL = "Yes" or "No">
You can also use the following code to either delete or run your tasks. Deleting it has the same effect as deleting the task via the ColdFusion Administrator.
<cfschedule action = "delete" task = "TaskName"> <cfschedule action = "run" task = "TaskName">