feat: status pages with custom domains, tls, themes and export (M7) #55
@@ -130,22 +130,17 @@ func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Tim
|
||||
for _, m := range want {
|
||||
wanted[m.ID.String()] = true
|
||||
}
|
||||
touched, err := s.rdb.HGetAll(ctx, keyTouched).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
recent := func(id string) bool {
|
||||
ms, err := strconv.ParseInt(touched[id], 10, 64)
|
||||
return err == nil && ms >= asOf.UnixMilli()
|
||||
}
|
||||
asOfMS := asOf.UnixMilli()
|
||||
ids, err := s.rdb.HKeys(ctx, keyIntervals).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
if !wanted[id] && !recent(id) {
|
||||
s.rdb.HDel(ctx, keyIntervals, id)
|
||||
s.rdb.HDel(ctx, keyTouched, id)
|
||||
if wanted[id] {
|
||||
continue
|
||||
}
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyIntervals, keyTouched}, id, asOfMS).Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
regions, err := s.rdb.SMembers(ctx, keyRegions).Result()
|
||||
@@ -158,14 +153,34 @@ func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Tim
|
||||
return err
|
||||
}
|
||||
for _, id := range members {
|
||||
if !byRegion[r][id] && !recent(id) {
|
||||
s.rdb.ZRem(ctx, keyDue(r), id)
|
||||
if byRegion[r][id] {
|
||||
continue
|
||||
}
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyDue(r), keyTouched}, id, asOfMS).Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pruneScript removes a monitor from a hash or sorted set unless it was
|
||||
// upserted at or after asOf. Checking and removing in one step closes the
|
||||
// window in which a concurrent upsert would be undone.
|
||||
//
|
||||
// KEYS: hash or sorted set to prune, touched hash. ARGV: monitor id, asOf ms.
|
||||
var pruneScript = redis.NewScript(`
|
||||
local touched = tonumber(redis.call('HGET', KEYS[2], ARGV[1]) or '0')
|
||||
if touched >= tonumber(ARGV[2]) then return 0 end
|
||||
if redis.call('TYPE', KEYS[1]).ok == 'zset' then
|
||||
redis.call('ZREM', KEYS[1], ARGV[1])
|
||||
else
|
||||
redis.call('HDEL', KEYS[1], ARGV[1])
|
||||
redis.call('HDEL', KEYS[2], ARGV[1])
|
||||
end
|
||||
return 1
|
||||
`)
|
||||
|
||||
// Heartbeat records that instance of region is alive.
|
||||
func (s *Scheduler) Heartbeat(ctx context.Context, region string, instance uuid.UUID) error {
|
||||
return s.rdb.ZAdd(ctx, keyInstances(region), redis.Z{Score: float64(s.now().UnixMilli()), Member: instance.String()}).Err()
|
||||
|
||||
Reference in new issue
Block a user