多个模板同时运行

发布于 2024-10-08 00:25:56 字数 156 浏览 0 评论 0原文

我已安排 Coldfusion 模板每 10 分钟运行一次,当上一次运行超过 10 分钟时,如何防止它运行。

不幸的是,当模板超时或出错时,我尝试在应用程序范围中使用计数器变量,计数器不会递减。

附言。是否有用于集成应用程序的 Coldfuison 框架(后端内容)

I have scheduled a coldfusion template to run every 10 minutes how do i prevent it from running when the previous run exceeds 10 minutes.

I've tried using a counter variable in the application scope unfortunately when the template times out or errors out the counter is not decremented.

PS. Is there a coldfuison framework for integrating applications (backend stuff)

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

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

发布评论

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

评论(2

白色秋天 2024-10-15 00:25:56

使用名为 cflock 的专有名称:

<cflock 
    timeout = "#createTimeSpan(0,0,0,1)#"
    name = "myProcess"
    throwOnTimeout = "no"
    type = "exclusive"> 
    <cfset start = now()>
    <!--- CFML to be synchronized. ---> 
    <cfset interval = 10 * 60> <!--- 10 minutes in seconds --->
    <cfif dateDiff("s", start, now()) GT interval>
        <cfhttp url="yourtemplate.cfm">
    </cfif>
</cflock>

这确保只有线程运行有问题的代码块。如果没有错误,同时访问一秒就会失败。

为了确保在先前超过时间间隔的情况下启动下一次运行,请跟踪锁内的开始时间,然后在结束时,如果超过时间间隔,则让 cflock 内的最后一条语句成为对其自身的 cfhttp 调用。

Use an exclusive named cflock:

<cflock 
    timeout = "#createTimeSpan(0,0,0,1)#"
    name = "myProcess"
    throwOnTimeout = "no"
    type = "exclusive"> 
    <cfset start = now()>
    <!--- CFML to be synchronized. ---> 
    <cfset interval = 10 * 60> <!--- 10 minutes in seconds --->
    <cfif dateDiff("s", start, now()) GT interval>
        <cfhttp url="yourtemplate.cfm">
    </cfif>
</cflock>

This ensures only thread ever runs the block of code in question. Simultaneous access will fail in one second without error.

To ensure the next run gets kicked off if the prior exceeds the time interval, track the start time inside the lock and then at the end, if its exceeded the interval, have the last statement inside the cflock be a cfhttp call to itself.

荆棘i 2024-10-15 00:25:56

您可以探索的一种可能的途径:

您可以设置一个数据库表来跟踪任务的进度。也许表名称为“task”,列为“taskName”和“inProgress”,后者是一个布尔值。当任务开始时,将 inProgress 设置为 true。完成后,将 inProgress 设置为 false。

在计划任务调用的模板中,首先检查指定任务的“inProgress”状态。如果是真的,那就放弃吧。否则,继续。

编辑:

嗯...在超时或错误的情况下,这实际上不会比应用程序变量更好。所以现在考虑使用时间戳而不是布尔值。当计划任务触发时,用当前时间更新该值。完成后,将其清除。

因此,当任务再次启动时,它将看到前一个任务已完成(空值),或者仍在进行中。 -如果-它仍在进行中,您可以对该值执行 dateDiff() 以查看它是否超过“x”分钟前。如果是,您可以假设前一个任务超时(或出错......但在这种情况下,我认为您可以在任务本身中进行一些错误处理)并运行任务的当前实例。

One possible route you could explore:

You could set up a database table to track the progress of the task. Maybe table name "task", with columns "taskName" and "inProgress", with the latter being a boolean. When the task starts, set inProgress to true. When it finishes, set inProgress to false.

In the template called by the scheduled task, have it first check the "inProgress" status of the specified task. If it's true, just abort. Otherwise, proceed.

EDIT:

Hmm... that actually wouldn't work any better than your application variables in the case of timeouts or errors. So now thinking that instead of a boolean, you use a timestamp. When the scheduled task fires, update the value with the current time. When it finishes, clear it out.

So when the task starts again, it will see that the previous task either finished (a null value), or it's still in progress. -If- it's still in progress, you can do a dateDiff() on the value to see if it was more than 'x' minutes ago. If it was, you can assume the previous task timed out (or errored out... but in that case I'd think you could put some error handling into the task itself) and run the current instance of the task.

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