每 45 分钟执行一次 Cron 表达式 [英] Cron expression to be executed every 45 minutes

查看:146
本文介绍了每 45 分钟执行一次 Cron 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个每 45 分钟触发一次的 cron 表达式.

I want a cron expression which fires every 45 minutes.

根据文档,我创建了这个 0 0/45 * * * ? 表达式.

According to the documentation, I have created this 0 0/45 * * * ? expression.

但它以 12:00、12:45、13:00、13:45、14:00 这样的模式触发.

But it is fired in a pattern like 12:00, 12:45, 13:00, 13:45, 14:00.

但我期望和想要的是在 12:00、12:45、13:30、14:15 被解雇.

But what I expect and want is to be fired at 12:00, 12:45, 13:30, 14:15.

我错过了什么?

推荐答案

Cron 并不是为了解决此类问题.它定义了必须触发触发器的确切日期和时间,而不是时间间隔.改用简单的时间表:

Cron is not meant to solve such problems. It defines the exact date and times, when a trigger must be fired, not intervals. Use a simple schedule instead:

TriggerBuilder.Create()
  .StartAt(startDate)
  .WithSimpleSchedule(
    simpleScheduleBuilder => simpleScheduleBuilder.WithIntervalInMinutes(45))
  .Build();

它要么是上面的简单计划,要么是多个 cron 触发器(Quartz 作业可以有多个触发器):

It's either a simple schedule as above, or multiple cron triggers (Quartz jobs can have multiple triggers):

0 0/45 12/3 * * ?    # 12:00, 12:45, 15:00, 15:45, ...
0 30 13/3 * * ?      # 13:30, 16:30, ...
0 15 14/3 * * ?      # 14:15, 17:15, ...

这篇关于每 45 分钟执行一次 Cron 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆