func (d *dataAccess) GetNextNotificationTime() (time.Time, error) { defer collect.StartTimer("redis", opentsdb.TagSet{"op": "GetNextNotificationTime"})() conn := d.GetConnection() defer conn.Close() m, err := redis.Int64Map(conn.Do("ZRANGE", pendingNotificationsKey, 0, 0, "WITHSCORES")) if err != nil { return time.Time{}, slog.Wrap(err) } // default time is one hour from now if no pending notifications exist t := time.Now().UTC().Add(time.Hour).Truncate(time.Second) for _, i := range m { t = time.Unix(i, 0).UTC() } return t, nil }
func (d *dataAccess) GetDueNotifications() (map[models.AlertKey]map[string]time.Time, error) { defer collect.StartTimer("redis", opentsdb.TagSet{"op": "GetDueNotifications"})() conn := d.GetConnection() defer conn.Close() m, err := redis.Int64Map(conn.Do("ZRANGEBYSCORE", pendingNotificationsKey, 0, time.Now().UTC().Unix(), "WITHSCORES")) if err != nil { return nil, slog.Wrap(err) } results := map[models.AlertKey]map[string]time.Time{} for key, t := range m { last := strings.LastIndex(key, ":") if last == -1 { continue } ak, not := models.AlertKey(key[:last]), key[last+1:] if results[ak] == nil { results[ak] = map[string]time.Time{} } results[ak][not] = time.Unix(t, 0).UTC() } return results, err }