如何在 ColdFusion 中获取计划任务列表和上次运行结果?

发布于 2024-08-22 20:44:19 字数 297 浏览 4 评论 0原文

我们正在尝试为我们的 cron 作业(CF、Java、SQLServer 等)构建一个仪表板,以便我们可以看到上次运行的时间、结果是什么以及计划下次运行的时间。

有没有办法使用 CFAdmin API 或一些未记录的 技巧来获取以下列表:

  1. 计划了哪些任务?
  2. 最后一次运行时间是多少?
  3. 成功了吗?
  4. 预计什么时候再次运行?

我们目前使用的是 CF8,但将在几周内升级到 CF9。

We're trying to build a dashboard for our cron jobs ---- CF, Java, SQLServer, etc. so that we can see when things were run last, what the result was, and when they're scheduled to run next.

Is there a way with the CFAdmin API or some undocumented <cfschedule> trick to get a list of:

  1. What tasks are scheduled?
  2. What the last run time was?
  3. Did it succeed?
  4. When is it scheduled to run again?

We're currently on CF8, but will be upgrading to CF9 within a few weeks.

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

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

发布评论

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

评论(3

灼痛 2024-08-29 20:44:19

我为你做了一些研究。我发现一个较旧的参考文献仍然有效,至少在 CF8 中,大概在 CF9 中也是如此。

<cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory">
<cfset allTasks = factory.CronService.listAll()/>
<cfloop index="i" from="1" to="#ArrayLen(allTasks)#">
    <cfdump var="#allTasks[i]#" />
</cfloop>

这回答了您的问题 #1 和 #4。
至于#3,这个问题没有答案。 ColdFusion的计划任务引擎只是在规定的时间加载指定的URL。没有成功或失败——它只是执行一个 HTTP 请求。

希望这有帮助。

I did a little research into this for you. I found a somewhat older reference that is still valid, at least in CF8 and presumably in CF9 as well.

<cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory">
<cfset allTasks = factory.CronService.listAll()/>
<cfloop index="i" from="1" to="#ArrayLen(allTasks)#">
    <cfdump var="#allTasks[i]#" />
</cfloop>

This answers your questions #1 and #4.
As for #3, there can be no answer to that. ColdFusion's scheduled task engine is just loading up the specified URL at the prescribed time. There is no success or fail -- it simply performs an HTTP request.

Hope this helps.

愛上了 2024-08-29 20:44:19

可以“发布”作业结果。 HTTP 请求的响应可以写入文件服务器,其中将包含上次运行作业的值。

<cfschedule action = "update"
    task = "TaskName" 
    operation = "HTTPRequest"
    url = "/index.cfm?action=task"
    startDate = "#STARTDATE#"
    startTime = "12:00:00 AM"
    interval = "Daily"
    resolveURL = "NO"
    requestTimeOut = "600"
    publish = "yes"
    path = "#PATH#"
    file = "log_file.log">

然后,如果需要,您可以根据数据库验证日志。由于它是来自页面的响应,因此您也可以在此处获取并存储错误和警告。

It is possible to "Publish" the results of the job. The response from the HTTP request can be written to the file server, and that will have the values of the last run job.

<cfschedule action = "update"
    task = "TaskName" 
    operation = "HTTPRequest"
    url = "/index.cfm?action=task"
    startDate = "#STARTDATE#"
    startTime = "12:00:00 AM"
    interval = "Daily"
    resolveURL = "NO"
    requestTimeOut = "600"
    publish = "yes"
    path = "#PATH#"
    file = "log_file.log">

Then you can verify the log against the database if you wanted. Since it is the response from the page, you can get and store errors and warnings here as well.

毅然前行 2024-08-29 20:44:19

@eric kolb 是对的 - 这就是以编程方式执行此操作的方法。如果您想更好地控制列表的反应方式,请尝试以下代码(本质上相同,但在 cfscript 中):

<cfscript>
scheduledTasksArray=ArrayNew(1);
taskService=createobject('java','coldfusion.server.ServiceFactory').getCronService();
scheduledTasksArray=taskservice.listall();

另外,要回答#2和#3(如果你做得正确的话,这几乎只是一个由两部分组成的问题):
当任务运行时,在顶部给自己发送一封电子邮件,说“嘿!我正在运行!!!”然后另一个人说“嘿!我完成了!!!”在任务代码的底部 - 您还可以添加时间戳来告诉它何时开始和停止(将其记录在数据库中也可以)。另外,要知道下次运行的时间,只需查看上次运行时间以及从 ServiceFactory 调用结果中返回的“间隔”字段即可。 (如果您需要进一步解释我的意思,请随时询问。

如果您还没有弄清楚您需要什么,希望这会有所帮助

@eric kolb is right - that is the way to do it programmatically. If you want more control over how the list reacts, try the following code (essentially the same, but in cfscript):

<cfscript>
scheduledTasksArray=ArrayNew(1);
taskService=createobject('java','coldfusion.server.ServiceFactory').getCronService();
scheduledTasksArray=taskservice.listall();

Also, to answer #2 and #3 (which is pretty much just one two-part question if you do it right):
When the task is run, send yourself an email right at the top saying "HEY! I'M RUNNING!!!!" and then another saying "HEY! I'M DONE!!!" at the bottom of the code for the task - you could add in a timestamp as well to tell when it started and stopped (logging this in a database works too). Also, to know when it will run next, just take a look at the last time AND the "interval" field gotten back from the results of the ServiceFactory call. (If you need further explanation on what I mean by this, feel free to ask.

Hope this helps if you haven't figured out what you needed to already

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