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:
@@ -301,30 +301,16 @@ func TestAlertDetectorDetectOnceNilSafe(t *testing.T) {
|
||||
// Should not panic
|
||||
}
|
||||
|
||||
func TestAlertDetectorStartDisabled(t *testing.T) {
|
||||
db := setupTestDB(t)
|
||||
func TestAlertDetectorRunOnceNilSafe(t *testing.T) {
|
||||
// Test nil detector
|
||||
var nilDetector *AlertDetector
|
||||
nilDetector.RunOnce(context.Background())
|
||||
|
||||
config := DefaultAlertDetectorConfig()
|
||||
config.Enabled = false
|
||||
// Test detector with nil db
|
||||
detector := &AlertDetector{}
|
||||
detector.RunOnce(context.Background())
|
||||
|
||||
detector := NewAlertDetector(db, db, nil, nil, config, nil)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
// Should return immediately without blocking
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
detector.Start(ctx)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
// Expected: Start returned immediately because Enabled=false
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
t.Error("Start did not return immediately when disabled")
|
||||
}
|
||||
// Should not panic
|
||||
}
|
||||
|
||||
func TestDetectMasterMinuteSpikesRPM(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user