时间范围的 Cron 表达式

发布于 2024-09-10 11:00:34 字数 125 浏览 7 评论 0原文

我正在使用 Quartz.Net 在我的应用程序中安排我的工作。我只是想知道是否可以构建以下场景的 CRON 表达式:

凌晨 2:15 到 5:20 之间的每一秒

I am using Quartz.Net to schedule my jobs in my application. I was just wondering if a CRON expression for the following scenario can be built:

Every second between 2:15AM and 5:20AM

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

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

发布评论

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

评论(3

眼眸印温柔 2024-09-17 11:00:34

robyaw,

非常感谢您的回答。对于如此延迟的回复,我深表歉意。我实际上已经休息了一段时间了。你的解决方案确实有效。我必须在指定的时间范围内创建 3 个 CRON 触发器。您提到的时间范围是正确的。但是,对于您提到的 3 个 CRON 表达式。我担心它们可能无法按预期工作。这些表达式适用于时间范围:2:15AM - 5:20AM - 每天

1) * 15-59 2 * * ? - 从 2:15AM 到 3:00AM 每秒,即 2: 15:00AM 至 2:59:59AM

2) * 0-59 3-4 * * ? - 每秒从 3:00AM 到 5:00AM,即 3:00:00AM 到 4: 59:59AM

3) * 0-19 5 * * ? - 从 5:00AM 到 5:20AM 每秒,即 5:00:00AM 到 5:19:59AM

@gauteh :请注意Quartz .Net 实际上支持第二个触发器。

希望这可以帮助其他可能需要解决类似问题的人。

robyaw,

Thanks a lot for your answer. And I apologize for such a delay in replying. I had actually been off for a while. Your solution indeed works. I had to create 3 CRON triggers for the time range that I had specified. You were right with the time ranges that you had mentioned. However, for the 3 CRON expressions that you had mentioned. I am afraid they might not work as intended. These expressions work for the time range : 2:15AM - 5:20AM - Everyday

1) * 15-59 2 * * ? - Every second from 2:15AM to 3:00AM, ie, 2:15:00AM to 2:59:59AM

2) * 0-59 3-4 * * ? - Every second from 3:00AM to 5:00AM, ie, 3:00:00AM to 4:59:59AM

3) * 0-19 5 * * ? - Every second from 5:00AM to 5:20AM, ie, 5:00:00AM to 5:19:59AM

@gauteh : Please note that Quartz .Net actually supports secondly trigger.

Hope this helps others who might need a solution to a similar problem.

作业与我同在 2024-09-17 11:00:34

关于 cron 秒支持,UNIX cron 工具之间使用的语法似乎存在一些差异和 CRON 表达式。然而,根据 Quartz CRON 文档,支持秒。

鉴于上述情况,我将创建三个 CRON 触发器来处理:

  1. 2:15:00 - 2:59:59
  2. 3:00:00 - 4:59:59
  3. 5:00:00 - 5:19:59

这将转换为(我相信):

  1. * 15/1 2 * * ?
  2. * * 3-5 * * ?
  3. * 0-20 5 * * ?

Regarding cron seconds support, there appears to be some difference in the syntax used between the UNIX cron tool and CRON Expression. According to the Quartz CRON Documentation however, seconds is supported.

Given the above, I would create three CRON Triggers to handle:

  1. 2:15:00 - 2:59:59
  2. 3:00:00 - 4:59:59
  3. 5:00:00 - 5:19:59

Which would translate to (I believe):

  1. * 15/1 2 * * ?
  2. * * 3-5 * * ?
  3. * 0-20 5 * * ?
我一直都在从未离去 2024-09-17 11:00:34

这里有一个间隔触发器(每秒),它可以干净地转换为 SimpleTrigger。您需要对其进行限制,仅允许其在特定时间范围(2:15 - 5:20)运行。您可以通过使用日历(更准确地说是 DailyCalendar)来实现这一点。您可以将每日日历设置为具有此时间范围,并将 InvertTimeRange 设置为 true 以包含该范围,而不是默认排除该范围。

教程DailyCalendar API 文档

You have here a interval trigger (every second) that translates cleanly to SimpleTrigger. What you need with it is a restriction to only allow it to run in specific time range (2:15 - 5:20). This you can achieve by using a calendar, more precisely a DailyCalendar. You can set daily calendar to have this time range and set the InvertTimeRange to true to include the range instead of default of excluding the range.

Read more about the calendars in the tutorial and DailyCalendar API documentation.

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