检查计划任务的运行状况?

发布于 2024-09-28 18:37:12 字数 124 浏览 0 评论 0原文

我们最近遇到一个问题,即在 Windows 升级和 CF 服务器重新启动后,ColdFusion 计划任务无法恢复。有没有办法监控计划任务的运行状况,并在它们运行不正常时发出警报?或者我是否需要编写一个任务来解析日志文件以获取该信息?

We recently had an issue where a ColdFusion scheduled task didn't resume after a Windows upgrade and a CF server restart. Is there a way to monitor the health of scheduled tasks and be alerted if they are not running properly? Or would I need to write a task to parse the log files for that information?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

任性一次 2024-10-05 18:37:12

您可以使用管理 API 来获取有关计划任务的信息。下面返回一个结构数组,其中包含有关每个计划任务的信息。然后您可以循环遍历数组并查看 last_run 变量。

<cfset arySchedTasks = createobject("java","coldfusion.server.ServiceFactory").getCronService().listall() />

you can use the admin api to get information on your scheduled tasks. the following returns an array of structures with info about each scheduled task. you can then loop through the array and look at the last_run variable.

<cfset arySchedTasks = createobject("java","coldfusion.server.ServiceFactory").getCronService().listall() />
爱的那么颓废 2024-10-05 18:37:12

如果您想检查计划任务是否在最一般的级别上运行,一种方法是计划一个“心跳”任务,按照您希望的频率运行。设置任务来更新计数器、更改时间戳、发送电子邮件、每天早上触发“我还活着”短信、添加日志条目 - 任何有意义的事情。这不会告诉您所有任务都在运行,但它会告诉您服务器处于活动状态,并且计划任务系统本身正在工作。

另一种选择是通过单一入口点(一种任务的前端控制器)来集中您的任务。这会将各个任务的设置和配置委托给您的代码,而不是 CF 管理员。您的主任务控制器将包括每个任务的触发代码。安排控制器根据需要频繁运行——因此,只执行一项任务,而不是多项任务。在控制器中,类似这样,也许每五分钟一次:

Check the time/date, compare against set of tasks
If time (or frequency) is A, run tasks P,Q,R, log success/failure
If time is B, run tasks S,T, log success/failure
If time is C, run tasks U,V,X, log success/failure    
Send heartbeat with success/failure codes for all relevant tasks

这种方法的一个优点是您可以表达更丰富的执行/不执行工作流程 - 让任务以半随机频率运行,根据成功或失败运行任务其他任务等。如果您看到/收到心跳指示器,您就知道您的任务控制器确实运行了。

If you want to check that scheduled tasks are working at the most general level, one way is to schedule a "heartbeat" task, running as frequently as you wish. Set the task to update a counter, change a timestamp, send an email, trigger an "I'm alive" SMS every morning, add a log entry -- whatever makes sense. This won't tell you that all your tasks are running, but it will tell you that the server is alive, and the scheduled task system itself is working.

Another option is to funnel your tasks through a single point of entry -- a sort of front-controller for tasks. This delegates the setup and configuration of individual tasks to your code, rather than the CF Administrator. Your master task controller would include triggering code for each task. Schedule the controller to run at as frequently as needed -- so, one single task, rather than many. In the controller, something like this, perhaps every five minutes:

Check the time/date, compare against set of tasks
If time (or frequency) is A, run tasks P,Q,R, log success/failure
If time is B, run tasks S,T, log success/failure
If time is C, run tasks U,V,X, log success/failure    
Send heartbeat with success/failure codes for all relevant tasks

One advantage to this approach is that you can express much richer go/no-go workflows -- have tasks run at semi-randomized frequencies, run tasks based on the success or failure of other tasks, etc. If you see/receive the heartbeat indicator, you know your task controller did in fact run.

拥有 2024-10-05 18:37:12

另一个简单的选择。为每个任务启用输出文件,并通过独立的 Cron 作业检查这些文件:如果文件在要求的时间范围内发生更改,则意味着调度程序任务已执行。

Another simple option. Enable the output file for each task and check these files by independent Cron job: if file was changed within required time span should mean that scheduler task was executed.

尴尬癌患者 2024-10-05 18:37:12

用户给出的关于找出正在运行的进程的建议非常出色。

>

使用此功能,我发现当我通过将 neo-cron.xml 从一台服务器复制到另一台服务器将计划任务从一台服务器移动到另一台服务器时,许多进程停止处理。当我使用计划任务列表查看进程时,我注意到正在运行的进程在密码字段中没有加密密码,而未运行的进程则具有加密密码,这会阻止进程运行,因为当进程运行时,它无法解密 neo-cron.xml 文件中的密码(因为它们来自不同的服务器,因此解密不起作用)。为了解决这个问题,我打开neo-cron.xml文件,手动取出每个配置文件密码部分中的所有密码,然后保存并用其中的密码替换该文件,然后重新启动CF服务。重新启动后,进程又开始自行运行。

我想分享这个以防其他人遇到同样的问题。如果您的任务在移动服务器后开始,请检查以确保 neo-cron.xml 文件中没有存储任何密码。

我花了很长时间才弄清楚这一点,所以希望这对其他人有帮助。

The suggestion that the user gave for finding out what processes are running is brilliant.

<cfset arySchedTasks = createobject("java","coldfusion.server.ServiceFactory").getCronService().listall() />

Using this, I found that when I moved the scheduled tasks from one server to another by copying the neo-cron.xml from one server to another many of the processes stopped processing. When I reviewed the processes using the scheduled task list, I noticed that the processes that WERE working didn't have encrypted passwords in the password field while the ones that DID NOT work had encrypted passwords that prevented the processes from running due to the fact that when the processes ran, it couldn't decrypt the passwords that were in the neo-cron.xml file (as they were from a different server and therefore the decryption didn't work). To solve this issue, I opened up the neo-cron.xml file and manually took out all of the passwords in the password section of each profile and then saved it and replaced the file with the passwords in it and then restarted the CF service. Once restarted, the processes started running again by themselves.

I wanted to share this in case anyone else was having the same issue. If your tasks are kicking off after moving servers, check to make sure there aren't any passwords store in the neo-cron.xml file.

It took my ages to figure this out, so hopefully this helps someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文