Skip to content

Commit

Permalink
fix: dedup window for unsent notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 21, 2024
1 parent 7602329 commit 4b8a226
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion db/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ func GetMatchingNotificationSilences(ctx context.Context, resources models.Notif
return silences, nil
}

func SaveUnsentNotificationToHistory(ctx context.Context, sendHistory models.NotificationSendHistory, window time.Duration) error {
func SaveUnsentNotificationToHistory(ctx context.Context, sendHistory models.NotificationSendHistory) error {
window := ctx.Properties().Duration("notifications.dedup.window", time.Hour*24)

return ctx.DB().Exec("SELECT * FROM insert_unsent_notification_to_history(?, ?, ?, ?, ?)",
sendHistory.NotificationID,
sendHistory.SourceEvent,
Expand Down
4 changes: 2 additions & 2 deletions notification/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func addNotificationEvent(ctx context.Context, id string, celEnv map[string]any,
SourceEvent: event.Name,
Status: models.NotificationStatusSilenced,
}
if err := db.SaveUnsentNotificationToHistory(ctx, history, ctx.Properties().Duration("notifications.dedup.window", time.Hour*24)); err != nil {
if err := db.SaveUnsentNotificationToHistory(ctx, history); err != nil {
return fmt.Errorf("failed to save silenced notification history: %w", err)
}

Expand All @@ -220,7 +220,7 @@ func addNotificationEvent(ctx context.Context, id string, celEnv map[string]any,
SourceEvent: event.Name,
Status: models.NotificationStatusRepeatInterval,
}
if err := db.SaveUnsentNotificationToHistory(ctx, history, time.Minute); err != nil {
if err := db.SaveUnsentNotificationToHistory(ctx, history); err != nil {
return fmt.Errorf("failed to save silenced notification history: %w", err)
}

Expand Down

0 comments on commit 4b8a226

Please sign in to comment.