react-code-dataset / goalert /engine /message /deduponcallnotifications.go
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame contribute delete
880 Bytes
package message
import (
"sort"
"github.com/target/goalert/notification"
)
// dedupOnCallNotifications will remove old on-call notifications if a newer one exists for the same schedule & destination.
func dedupOnCallNotifications(messages []Message) ([]Message, []string) {
toProcess, result := splitPendingByType(messages, notification.MessageTypeScheduleOnCallUsers)
sort.Slice(toProcess, func(i, j int) bool { return toProcess[i].CreatedAt.After(toProcess[j].CreatedAt) })
type msgKey struct {
scheduleID string
dest notification.DestID
}
m := make(map[msgKey]struct{})
var toDelete []string
for _, msg := range toProcess {
key := msgKey{scheduleID: msg.ScheduleID, dest: msg.DestID}
if _, ok := m[key]; ok {
toDelete = append(toDelete, msg.ID)
continue
}
m[key] = struct{}{}
result = append(result, msg)
}
return result, toDelete
}