什么是定时任务
您是否遇到以下问题?
- 希望每天夜间自动发布更新的内容
- 希望某个固定时间基于最新的数据自动进行发布/训练
针对上述类似的期刊工作,我们开发了定时任务功能。
- 可选的发布/调试
- 可选FAQ/对话流图
- 任务启用/暂停
- 多个任务同时存在
- 任务在指定日期内生效
支持两种循环模式:
- Cron 表达式
- 固定时间间隔
Cron 表达式
cron 表达式是由 6 或 7 个由空格分隔的字段组成的字符串。 字段可以包含任何允许的值,以及该字段允许的特殊字符的各种组合。 字段如下:
字段名 | 是否必填 | 填入的值 | 允许的特殊符号 |
---|---|---|---|
Seconds | YES | 0-59 | , - * / |
Minutes | YES | 0-59 | , - * / |
Hours | YES | 0-23 | , - * / |
Day of month | YES | 1-31 | , - * ? / L W |
Month | YES | 1-12 or JAN-DEC | , - * / |
Day of week | YES | 1-7 or SUN-SAT | , - * ? / L # |
Year | NO | empty, 1970-2099 | , - * / |
所以 cron 表达式可以像这样简单: * * * * ? *
或者更复杂,像这样: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2002-2010
例子
以下是一些完整的示例:
Expression | Meaning |
0 0 12 * * ? | Fire at 12pm (noon) every day |
0 15 10 ? * * | Fire at 10:15am every day |
0 15 10 * * ? | Fire at 10:15am every day |
0 15 10 * * ? * | Fire at 10:15am every day |
0 15 10 * * ? 2005 | Fire at 10:15am every day during the year 2005 |
0 * 14 * * ? | Fire every minute starting at 2pm and ending at 2:59pm, every day |
0 0/5 14 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day |
0 0/5 14,18 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day |
0 0-5 14 * * ? | Fire every minute starting at 2pm and ending at 2:05pm, every day |
0 10,44 14 ? 3 WED | Fire at 2:10pm and at 2:44pm every Wednesday in the month of March. |
0 15 10 ? * MON-FRI | Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday |
0 15 10 15 * ? | Fire at 10:15am on the 15th day of every month |
0 15 10 L * ? | Fire at 10:15am on the last day of every month |
0 15 10 L-2 * ? | Fire at 10:15am on the 2nd-to-last last day of every month |
0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
0 15 10 ? * 6L 2002-2005 | Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005 |
0 15 10 ? * 6#3 | Fire at 10:15am on the third Friday of every month |
0 0 12 1/5 * ? | Fire at 12pm (noon) every 5 days every month, starting on the first day of the month. |
0 11 11 11 11 ? | Fire every November 11th at 11:11am. |
欲了解更多详情,请访问 quartz-scheduler
固定时间间隔
定期执行以秒为单位的固定间隔执行。
概念
常用设置:
- 模式:固定时间间隔或 Cron
- 启用:是否启用该任务
- 训练类型:调试或发布
- 可培训模块:可发布/调试的模块
- 任务执行时间间隔:在此时间段内可以运行任务
可选设置:
- 固定时间间隔:
需要设置`固定时间间隔(秒)`
- 正整数
- 最小值:100
- 克罗恩表达式:
需要设置`自定义(Corn)`
- 有效的 cron 表达式