Do scheduled tasks load the Application.cfc in the same way as web pages? We have a task which runs nightly and needs to use a services cfc loaded into the application. Will the application scope exist in the same way as it does when calling a standard web page? Are there any differences or gotchas to watch out for?
The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. Task Scheduler does this by monitoring whatever criteria you choose (referred to as triggers) and then executing the tasks when those criteria are met.
Open Start, Search for "Task Scheduler" and press enter to open "Task Scheduler". Right-click on the "Task Scheduler Library" and click on the "New Folder" option. Enter the name of the New folder and click on the "OK" button. Navigate the following: Task Scheduler Library > New Folder, then click on "Create Task".
There are two different folders labeled "tasks". The first folder is relative to the scheduled tasks that would appear in the task scheduler, these are in c:\windows\tasks. The second tasks folder is located in c:\windows\system32\tasks.
In the Task Scheduler window click "Create Task" on the right hand bar under the "Actions" pane. In the "Create Task" dialog click the "Change User or Group" button. Make sure "From this location" is set to the local machine name (to change click "Locations" button and select the local computer name)
The CF task scheduler makes an HTTP call to the URL you specify in the task, so all standard rules apply. Application.cfm/application.cfc is run, the app scope exists, and so forth.
The only thing, offhand, you need to keep in mind is that the scheduler itself doesn't recognize errors, so you should write the task in such a way that it logs, emails, etc. on error. And, during testing, probably on success.
Edit: Sergii noted something I'd overlooked. The scheduler doesn't maintain cookies. It acts more like a spider. Therefore, anything in the session or client scopes or written to cookies won't actually be stored, and will be lost next time the action is run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With