John Weber
John Weber

Reputation: 193

Coldfusion: Detecting if being run by the scheduler

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.isScheduled = 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);

Upvotes: 5

Views: 1457

Answers (4)

Jason Talbott
Jason Talbott

Reputation: 11

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)

Upvotes: 1

Rob
Rob

Reputation: 11

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.

Upvotes: 0

Rex Aglibot
Rex Aglibot

Reputation: 56

Check for the user agent. The user agent is "CFSCHEDULE" but please confirm this first.

Upvotes: 4

prashant
prashant

Reputation: 1

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"....

Upvotes: 0

Related Questions