mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
refactor(cron): migrate cron jobs to foundation scheduler
Replace custom goroutine-based scheduling in cron jobs with centralized foundation scheduler. Each cron job now exposes a RunOnce method called by the scheduler instead of managing its own ticker loop. Changes: - Remove interval/enabled config from cron job structs - Convert Start() methods to RunOnce() for all cron jobs - Add scheduler setup in main.go with configurable intervals - Update foundation dependency to v0.6.0 for scheduler support - Update tests to validate RunOnce nil-safety
This commit is contained in:
@@ -34,7 +34,7 @@ func TestLogCleanerRetentionDeletesOld(t *testing.T) {
|
||||
t.Fatalf("create fresh: %v", err)
|
||||
}
|
||||
|
||||
cleaner := NewLogCleaner(db, nil, 1, 0, time.Minute, nil)
|
||||
cleaner := NewLogCleaner(db, nil, 1, 0, nil)
|
||||
if err := cleaner.cleanOnce(context.Background()); err != nil {
|
||||
t.Fatalf("clean once: %v", err)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func TestLogCleanerMaxRecordsKeepsLatest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
cleaner := NewLogCleaner(db, nil, 0, 3, time.Minute, nil)
|
||||
cleaner := NewLogCleaner(db, nil, 0, 3, nil)
|
||||
if err := cleaner.cleanOnce(context.Background()); err != nil {
|
||||
t.Fatalf("clean once: %v", err)
|
||||
}
|
||||
@@ -85,3 +85,15 @@ func TestLogCleanerMaxRecordsKeepsLatest(t *testing.T) {
|
||||
t.Fatalf("expected min id >= 3, got %d", min.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogCleanerRunOnceNilSafe(t *testing.T) {
|
||||
// Test nil cleaner
|
||||
var nilCleaner *LogCleaner
|
||||
nilCleaner.RunOnce(context.Background())
|
||||
|
||||
// Test cleaner with nil db
|
||||
cleaner := &LogCleaner{}
|
||||
cleaner.RunOnce(context.Background())
|
||||
|
||||
// Should not panic
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user