Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion: Detecting if being run by the scheduler

Tags:

coldfusion

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);

like image 252
John Weber Avatar asked Jul 22 '11 13:07

John Weber


People also ask

How do I know if Task Scheduler is running?

Right-click the Task Scheduler service, and then click Properties. On the General tab, make sure that the startup type is set to automatic, and that the service status is Started. If the service is not running, click Start.

How does PCF scheduler work?

Scheduler for PCF is a service for scheduling the execution of Diego tasks, such as database migrations, emails, or batch jobs, as well as the execution of outbound HTTP calls. Scheduler for PCF enables developers to do the following: Create, run, and schedule jobs and view job history.


2 Answers

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

like image 148
Rex Aglibot Avatar answered Sep 30 '22 07:09

Rex Aglibot


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)

like image 42
Jason Talbott Avatar answered Sep 30 '22 08:09

Jason Talbott