v1.1.0 Release Notes
Released
Features
Custom Dependency Timeout
- Specify timeout via
Wait{ID: taskID, Delay: duration} - Default timeout is 1 minute when not configured
Dependency Failure Handling Strategy
- Added
StopandSkiphandling modesStop: Halt entire dependency chain on failure (default)Skip: Skip failed dependency and continue executing current task
- Configure failure behavior via
Wait{ID: taskID, State: Skip}
Examples
- // Failure handling strategy
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []Wait{
- {ID: taskA, State: Skip}, // Skip if taskA fails, continue execution
- {ID: taskB, State: Stop}, // Stop if taskB fails (default)
- })
- // Custom timeout + failure strategy combination
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []Wait{
- {ID: taskA, Delay: 30 * time.Second, State: Skip}, // Wait 30s, skip on failure
- {ID: taskB, Delay: 10 * time.Second, State: Stop}, // Wait 10s, stop on failure
- })
- // Legacy version (deprecated in v2.*.*)
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []int64{taskA, taskB})
Refactor
Compatibility Guarantee
- Legacy code runs without modification
- Maintains
[]int64dependency support (deprecated inv2.*.*) WaitStatezero value isStop, ensuring default behavior unchanged
Deprecation Notice
Features Removed in v2.*.*
[]int64format: Migrate to[]Waitformat for full feature support- // Old format
- []int64{taskA, taskB}
- // New format
- []Wait{{ID: taskA}, {ID: taskB}}
新增
自定義依賴超時時間
- 透過
Wait{ID: taskID, Delay: duration}指定超時時間 - 未設定時預設超時為 1 分鐘
依賴失敗處理策略
- 新增
Stop和Skip兩種處理方式Stop: 依賴失敗時停止整個依賴鏈(預設)Skip: 依賴失敗時跳過失敗的依賴,繼續執行當前任務
- 透過
Wait{ID: taskID, State: Skip}設定失敗行為
範例
- // 失敗處理策略
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []Wait{
- {ID: taskA, State: Skip}, // taskA 失敗時跳過,繼續執行
- {ID: taskB, State: Stop}, // taskB 失敗時停止(預設)
- })
- // 自定義超時 + 失敗策略組合
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []Wait{
- {ID: taskA, Delay: 30 * time.Second, State: Skip}, // 等待 30 秒,失敗時跳過
- {ID: taskB, Delay: 10 * time.Second, State: Stop}, // 等待 10 秒,失敗時停止
- })
- // 舊版本(將在 v2.*.* 廢棄)
- taskID, _ := scheduler.Add("@daily", func() error {
- return processData()
- }, "Data processing", []int64{taskA, taskB})
重構
相容性保證
- 舊版本代碼無需修改即可正常運行
- 保留
[]int64依賴支援(將在v2.*.*廢棄) WaitState零值為Stop,確保預設行為不變
棄用預告
將在 v2.*.* 移除的功能
[]int64格式:建議遷移至[]Wait格式以獲得完整功能支援- // 舊格式
- []int64{taskA, taskB}
- // 新格式
- []Wait{{ID: taskA}, {ID: taskB}}