DEV Community

邱敬幃 Pardn Chiu
邱敬幃 Pardn Chiu

Posted on

A lightweight go-cron (v1.1.0)

cover


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 Stop and Skip handling modes
    • Stop: 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})
Enter fullscreen mode Exit fullscreen mode

Refactor

Compatibility Guarantee

  • Legacy code runs without modification
  • Maintains []int64 dependency support (deprecated in v2.*.*)
  • WaitState zero value is Stop, ensuring default behavior unchanged

Deprecation Notice

Features Removed in v2.*.*

  • []int64 format: Migrate to []Wait format for full feature support
  // Old format
  []int64{taskA, taskB}

  // New format
  []Wait{{ID: taskA}, {ID: taskB}}
Enter fullscreen mode Exit fullscreen mode

©️ 2025 邱敬幃 Pardn Chiu

Top comments (0)