views:

99

answers:

1

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?

+12  A: 

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.

Ben Doom
Only difference is that new Session is created on each request.
Sergii
This is funny, I have had inconsistent results using application scope variables set from Application.cfc in a scheduled task. Based on this, I am going to re-investigate those problem, which I have worked around before.
Jay
I've seen weirdness as well, which is why I tend to make my scheduled tasks self-contained. I think some of the methods aren't firing when it's a headless browser request, like OnSessionStart() or OnRequestStart().
Al Everett
I've never had problems with application scope issues, but (I think) I've only used application.cfm for scheduled tasks.
Ben Doom