cfschedule

Provides a programmatic interface to the CFML scheduling engine. Can run a CFML page at scheduled intervals, with the option to write the page output to a static HTML page. This feature enables you to schedule pages that publish data, such as reports, without waiting while a database transaction is performed to populate the page.

  <cfschedule action="delete" task="">

 cfschedule(action="delete", task="");

Attribute Reference

action string
Required

delete: deletes the specified task
update: updates an existing task or creates a new task, if one with the name specified by the task attribute does not exist
run: executes the specified task
pause: Pauses the specified task.
resume: Continues executing the specified task.
list: Lists all the scheduled tasks.
pauseall: CF 10+ Pauses all scheduled tasks.
resumeall: CF 10+ Resume all scheduled tasks for a particular application.
create: CF2018u2+ Create a fresh task. If a task already exists, an error is thrown.
modify: CF2018u2+ Modifies an existing task while retaining its old values.
Values:
  • delete
  • update
  • run
  • pause
  • resume
  • list
  • pauseall
  • resumeall
  • create
  • modify

task string

Name of the task. Not required if action attribute is set to list, otherwise it is required.

operation string
Default: HTTPRequest

Operation that the scheduler performs. Must be HTTPRequest.

file string

Name of the file in which to store the published output of the scheduled task.

path string

Path to the directory in which to put the published file.
NOTE: This is Required if publish is "Yes".

startdate string

Date on which to first run the scheduled task.

starttime string

Time at which to run the scheduled of task starts.

URL string

URL of the page to execute.

port numeric
Default: 80

Port to use on the server that is specified by the url parameter. If resolveURL = "yes", retrieved document URLs that specify a port number are automatically resolved, to preserve links in the retrieved document. A port value in the url attribute overrides this value.

publish boolean
Default: false

Yes: save the result to a file
No: does not

endDate string

Date when scheduled task ends.

endTime numeric

Time when scheduled task ends (seconds).

interval string

Interval at which task is scheduled.
* number of seconds (minimum is 60)
* once
* daily
* weekly
* monthly
Values:
  • once
  • daily
  • weekly
  • monthly

requesttimeout numeric

Deprecated as of CF 11+, Removed in CF2018 Used to extend the default timeout period.

username string

Username, if URL is protected.

password string

Password, if URL is protected.

proxyserver string

Host name or IP address of a proxy server.

proxyport numeric
Default: 80

Port number to use on the proxy server.

proxyuser string

User name to provide to the proxy server.

proxypassword string

Password to provide to the proxy server.

resolveurl boolean
Default: false

Yes: resolve links in the output page to absolute references
No: does not

group string
Default: default

CF 11+ The group to which the scheduled task belongs.

mode string
Default: server

CF 10+ If the task is server-specific or application specific.
Values:
  • application
  • server

result (CF10+)/returnvariable (lucee) query

Name for the query in which cfschedule returns the result variables.
NOTE: Required for action="list"

eventHandler string

CF 10+ A CFC file which implements CFIDE.scheduler.ITaskEventHandler and is invoked for events while running the task.
Note: CF 2018 Enterprise Required; not supported in Standard Edition

onException string
Default: invokeHandler, if eventHandler is specified

CF 10+ Specify the action to take if a task results in error.
Note: CF 2018 Enterprise Required; not supported in Standard Edition
Values:
  • refire
  • pause
  • invokeHandler

onComplete string
Default: invokeHandler

CF 10+ The action or task to perform after completion of the current task. Can be used to chain dependent tasks by executing a task after this task completes.
Note: CF 2018 Enterprise Required; not supported in Standard Edition

onMisfire string
Default: invokeHandler if eventHandler is specified

CF 10+ Specify what to do if a task misfires. If unspecified, then no action is taken.
Note: CF 2018 Enterprise Required; not supported in Standard Edition
Values:
  • fire_now
  • invokeHandler

cronTime numeric

CF 10+ Schedule the task time in quartz cron expression format (6 or 7 space-seperated values). Format is: second, minute, hour, day of month, month, day of week, year. Second value is required, as are the rest, but year is optional.

repeat string
Default: -1

CF 10+ Specify the number of times a given schedule has to repeat.

retryCount numeric
Default: 3

CF 10+ Specify the number of times to retry the task if the task fails. Must be between 0 and 3, inclusive.
Values:
  • 0
  • 1
  • 2
  • 3

priority numeric
Default: 5

CF 10+ Set the priority of this task.

exclude string

CF 10+ Comma-separated list of dates or date range on which to not execute the scheduled task.

cluster boolean
Default: no

CF 10+ If yes, the task can be executed in a cluster setup.
Note: CF 2018 Enterprise Required; not supported in Standard Edition

overwrite boolean
Default: true

CF 10+ Specify whether to overwrite the output files on task execution (if true) or create new output files (if false).

unique boolean
Default: true

lucee4.5+ If true, the scheduled task is only executed once at time. If a task is still running from previous round no new task is started.

autodelete boolean

lucee4.5+ If set to true, the scheduled task will be deleted when there is no possible future execution.

readonly boolean

lucee4.5+ If true, the scheduled task can not be modified or deleted in the Lucee Administrator.

Links more information about cfschedule

Examples
Sample code using the cfschedule tag

Tell ColdFusion to run 'importData.cfm' daily at 7AM

<cfschedule
 action="update"
 task="importMyCSVFileToDB"
 operation="HTTPRequest"
 startDate="5/12/2016"
 startTime="7:00 AM"
 url="http://www.mydomain.com/scheduled/importData.cfm"
 interval="daily" />

Delete the task 'importMyCSVFileToDB' from the list of ColdFusion scheduled jobs

<cfschedule
 action="delete"
 task="importMyCSVFileToDB" />

CF 10+ Instruct ACF not to execute the task on the set date, date range, or list of dates

<cfschedule
 action="update"
 task="sendClientReportEmail"
 exclude="12/24/2019 TO 1/2/2020" />

CF 10+ Execute a task every 2 minutes from 3:00 AM to 10:00 AM and 9:00 PM to 11:58 PM daily

<cfschedule
 action="update"
 task="myTaskName"
 cronTime="0 */2 3-10,21-23 * * ?" />

List and dump all scheduled tasks running in ColdFusion instance

<cfschedule
 action="list"
 result="scheduledList"
 />
<cfdump var="#scheduledList#" />

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub