本文介绍了如何确定计划任务是自动运行还是在浏览器中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一些代码作为计划任务,在CF管理器中设置。

I am running some code as a scheduled task, setup in CF Administrator.

有一种方法告诉代码,代码作为计划任务运行,是否通过单击CF管理员计划任务区域中的运行图标运行,或者是否在浏览器中直接调用它?

Is there a way to tell in the code that the code ran as a scheduled task, whether it was ran by clicking the run icon in the CF Administrator scheduled task area, or whether it was called directly in a browser?

添加其他变量不会工作?

Adding additional variables will not work?

推荐答案

从CF管理员的测试链接



请询问您是否可以识别通过单击coldfusion管理中的测试链接手动运行的计划任务或按计划运行的计划任务之间的差异,可以启用计划任务的日志记录。任何由用户运行任务的日志条目将会说 [作业名]由于用户请求在{timestamp} 执行。如果它自然运行,日志条目将会说 [job of job]在{timestamp}执行

From the test link in the CF admin

If you're asking if you can identify the difference between a scheduled task being run manually by clicking the test link in the coldfusion admin or run on schedule, you can enable logging of scheduled tasks. Any time the task is run by the user the log entry will say [name of job] Executing because of user request at {timestamp}. If it ran naturally, the log entry will say [name of job] Executing at {timestamp}

ve寻找一个方法来告诉代码,我找不到任何东西。它将取决于调度程序的准确性,但是您可以查看now()是否等于调度的时间。类似的东西(伪代码):

I've looked for a way to tell by code and I can't find anything. It would depend on the accuracy of the scheduler but you could look to see if now() is equal to the time of the schedule. Something like (pseudo code):

<!--- disclaimer: I've heard stories that cfschedule sometimes runs a little late --->
<cfset scheduleTime = "2:00 am">
<cfif cgi.HTTP_USER_AGENT eq "CFSCHEDULE" and timeFormat(now(), "h:mm tt") eq scheduleTime>
   <!--- ran naturally --->
<cfelse>
   <!--- ran by force --->
</cfif>



从浏览器



要知道您的计划任务是否按计划运行,或者如果文件被浏览器命中,您可以查看 cgi.HTTP_USER_AGENT 。如果它由调度程序运行,它将等于 CFSCHEDULE 否则它将等于客户端设置发送。

From a browser

If you want to know if your scheduled task was run by the schedule or if the file was hit by the browser you can look at cgi.HTTP_USER_AGENT. if it is run by the scheduler it will equal CFSCHEDULE otherwise it will equal whatever the client is set to send.

也许, Mozilla / 5.0(Windows NT 5.1)AppleWebKit / 537.11(KHTML,像Gecko)Chrome / 23.0.1271.97 Safari / 537.11

Perhaps, Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11

或者如果你很幸运有一个机器人命中它,像: Mozilla / 5.0(compatible; MJ12bot /v1.4.3; http://www.majestic12.co.uk/bot.php?+)

or if you're lucky enough to have a bot hit it, something like: Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)

这是可能欺骗客户端或服务器请求,使用户用户代理说CFSCHEDULE,但不太可能。

It is possible to spoof the client or server request to make the user user agent to say CFSCHEDULE but it isn't likely.

cfhttp的默认用户代理是COLDFUSION,以防感兴趣。

The default user agent for cfhttp is "COLDFUSION", in case you were interested.

这篇关于如何确定计划任务是自动运行还是在浏览器中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:55