@@ -459,6 +459,11 @@ func (tm *taskMaster) readFiles(ctx context.Context) {
459459func (tm * taskMaster ) handleNotifications (taskChan chan task.Task , ctx context.Context ) {
460460 sendChan := make (chan struct {})
461461 var alerts []cache.AlertRecord
462+
463+ // Initialize lastAlertTime to today at 00:00:00 (zero hour)
464+ now := time .Now ()
465+ lastAlertTime := time .Date (now .Year (), now .Month (), now .Day (), 0 , 0 , 0 , 0 , now .Location ())
466+
462467 go func () {
463468 dur := tm .slack .MinFrequency
464469 for ; ; time .Sleep (dur ) {
@@ -467,20 +472,23 @@ func (tm *taskMaster) handleNotifications(taskChan chan task.Task, ctx context.C
467472 // Check for incomplete tasks and add them to alerts
468473 tm .taskCache .CheckIncompleteTasks ()
469474
470- // Get all alerts (including newly added incomplete task alerts)
471- alerts , err = tm .taskCache .GetAlertsByDate ( time . Now () )
475+ // Get NEW alerts only - those after the last time we sent
476+ alerts , err = tm .taskCache .GetAlertsAfterTime ( lastAlertTime )
472477 if err != nil {
473478 log .Printf ("failed to retrieve alerts: %v" , err )
474479 continue
475480 }
476481
477482 if len (alerts ) > 0 {
478483 sendChan <- struct {}{}
484+ // Update lastAlertTime to now (before we send, so we don't miss any)
485+ lastAlertTime = time .Now ()
479486 if dur *= 2 ; dur > tm .slack .MaxFrequency {
480487 dur = tm .slack .MaxFrequency
481488 }
482489 log .Println ("wait time " , dur )
483490 } else if dur != tm .slack .MinFrequency {
491+ // No NEW alerts - reset to minimum frequency
484492 dur = tm .slack .MinFrequency
485493 log .Println ("Reset " , dur )
486494 }
0 commit comments