MCPcopy
hub / github.com/PatchMon/PatchMon / allowRate

Method allowRate

server-source-code/internal/notifications/emitter.go:413–425  ·  view source on GitHub ↗
(tenantHost, destinationID string)

Source from the content-addressed store, hash-verified

411}
412
413func (e *Emitter) allowRate(tenantHost, destinationID string) bool {
414 ctx := context.Background()
415 min := time.Now().Unix() / 60
416 key := tenantRedisKey(tenantHost, fmt.Sprintf("notif:rl:%s:%d", destinationID, min))
417 n, err := e.rdb.Incr(ctx, key).Result()
418 if err != nil {
419 return true
420 }
421 if n == 1 {
422 _ = e.rdb.Expire(ctx, key, 2*time.Minute).Err()
423 }
424 return n <= ratePerMinute
425}
426
427// cancelPairs maps an event type to the delayed event type it should cancel.
428// When host_recovered fires, any pending delayed host_down notification for the same reference should be suppressed.

Callers 2

emitMethod · 0.95
EnqueueToDestinationMethod · 0.95

Calls 1

tenantRedisKeyFunction · 0.85

Tested by

no test coverage detected