1

Is there a way to detect if a script is runned by a scheduled task.

I have a script which gives throws a ClientAbortException because I am using cfflush. I need to detect if the script is running via a scheduled task so the script can run successfully.

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
  • 1
    this is a duplicate qustion http://stackoverflow.com/questions/13977831/how-do-i-determine-if-a-scheduled-task-was-ran-automatically-or-ran-in-a-browser/13978558#13978558 – genericHCU Feb 07 '13 at 11:25
  • Here's something to look at regarding the error - http://stackoverflow.com/questions/12141659/connection-reset-by-peer-socket-write-error-cfcontent-on-coldfusion-10. Seems odd, as it seems to imply that the task scheduler is terminating the connection to the server after the request is made but before it is complete. – Barry Feb 08 '13 at 18:40
  • And you might also consider using cgi.remote_addr to determine if it is a scheduled task. It contains the IP address of the remote host making the request. For a scheduled task, it will be the IP address of your server. – Barry Feb 08 '13 at 18:43
  • 1
    @barry The drawback here is when you have multiple instances of your app deployed over multiple server, you need to configure the IP-address somewhere to check if the CGI.REMOTE_ADDR is equal. BTW, i found a bugreport regarding the error: https://issues.jboss.org/browse/RAILO-727 – Willem de Wit Feb 11 '13 at 08:10

2 Answers2

3

It seems that you can check it via CGI.HTTP_USER_AGENT:

<cfif CGI.HTTP_USER_AGENT NEQ "CFSCHEDULE">
  <cfflush>
</cfif>
Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
1

This is a duplicate question as Travis said, but another answer is you could add a url parameter to the scheduled task something like ?auto= which would allow you to check the url scope to determine how it was ran.

Matt Busche
  • 14,216
  • 5
  • 36
  • 61