feat(schedule): 任务支持「每天定时 / 每周定时」,用选择器而不是手写 cron
- schedule.py: 新增调度计算模块(纯函数,便于单测)。三种模式:interval(每 N 分钟)/ daily(选钟点)/ weekly(选星期 + 钟点) - 钟点模式是「固定时刻」而非「固定延迟」——从日历重算,所以某轮跑晚了不会把之后每一轮都拖晚。interval 保持原语义:从上一轮开始计时 - 抖动只加给 interval。给「每天 9:00」也加抖动就成了 9:00–9:01 随机触发,操作者选的时间被悄悄改掉,只会像 bug - 模型 / schema / service: 新增 schedule_mode / schedule_hours / schedule_days / schedule_minute。时钟字段存逗号分隔文本——几个小整数、永远整体读写,单开一张表只会换来 join。interval_minutes 保留且仍是默认值,已有任务不受影响 - service: 改动任何调度字段都按合并后的状态重算 next_run_at。重新启用也算改动,否则停用一个月再打开会带着一个月前的 next_run_at,一保存就立即触发 - 前端: 运行方式三选一 + 小时/星期胶囊多选 + 分钟下拉,并实时预览结果句子。任务卡片改显示后端拼好的 schedule_label,避免列表和编辑器对同一计划给出两种说法 - 校验: 钟点模式至少选一个时间,按周至少选一个星期 tests/test_schedule.py 新增 24 个用例,含「恰好等于当前时刻的档位归属下一天」这个会让调度器自循环的边界。
This commit is contained in:
@@ -28,6 +28,14 @@ export interface MonitorTarget {
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* How a task is scheduled.
|
||||
*
|
||||
* All three are expressible with pickers. A cron string is deliberately not
|
||||
* supported -- it is a small language to learn just to say "every day at nine".
|
||||
*/
|
||||
export type ScheduleMode = 'interval' | 'daily' | 'weekly'
|
||||
|
||||
export interface MonitorTask {
|
||||
id: number
|
||||
name: string
|
||||
@@ -35,6 +43,15 @@ export interface MonitorTask {
|
||||
mode: MonitorMode
|
||||
enabled: boolean
|
||||
interval_minutes: number
|
||||
schedule_mode: ScheduleMode
|
||||
/** 0-23. Empty in interval mode. */
|
||||
schedule_hours: number[]
|
||||
/** 0-6 with Monday = 0, matching Python's `date.weekday()`. Weekly only. */
|
||||
schedule_days: number[]
|
||||
/** Minute past the hour, shared by every time in the schedule. */
|
||||
schedule_minute: number
|
||||
/** Composed by the backend, so the list and the editor cannot disagree. */
|
||||
schedule_label: string
|
||||
max_notes_count: number
|
||||
enable_comments: boolean
|
||||
max_comments_count: number
|
||||
@@ -195,6 +212,10 @@ export interface TaskCreatePayload {
|
||||
name: string
|
||||
mode: MonitorMode
|
||||
interval_minutes: number
|
||||
schedule_mode: ScheduleMode
|
||||
schedule_hours: number[]
|
||||
schedule_days: number[]
|
||||
schedule_minute: number
|
||||
max_notes_count: number
|
||||
enable_comments: boolean
|
||||
max_comments_count: number
|
||||
|
||||
Reference in New Issue
Block a user