Is there a way for a ColdFusion app to know whether it is being run from the scheduler vs. from a browser? Ideally, I'd like to set a Session flag, for instance "isScheduled" in Application.cfm to be used throughout the app.
EDIT I ended up checking the user agent, and that it is being run locally (to improve security), and (since it is running in Application.cfm) that the page is in the folder which allows scheduling:
Request.isS开发者_运维问答cheduled = FindNoCase("CFSCHEDULE",CGI.HTTP_USER_AGENT)
and (Find("10.",CGI.REMOTE_ADDR)==1
or Find("198.162.",CGI.REMOTE_ADDR)==1)
and FindNoCase("scheduled",CGI.CF_TEMPLATE_PATH);
Check for the user agent. The user agent is "CFSCHEDULE" but please confirm this first.
I nest my Application.cfm logic in a cfif, that checks to see if a parameter ('cron') is defined. If it is, then it skips all of the rest of the logic in Application like authentication, header crap, etc.
Then when I set up the scheduled tasks I pass in the URL I want to hit with the cron parameter (http://mysite.com/scheduledtasks.cfm?cron=yo)
I am not sure but if application run through scheduler then cgi.remote_address must be same for all request that you can track.....and mark "isSchedule"....
It's a common practice to let the task scheduler run a list of tasks which in tern trigger the actual tasks. I.e. you ran "dailytask.cfm which cfincludes the task that you want to run. You can now add url.parameters or other things to it to identify the source of the trigger.
精彩评论