(actor ActorIdentity, taskID string, now time.Time, limit int)
| 41 | } |
| 42 | |
| 43 | func (l *forceRunRateLimiter) allow(actor ActorIdentity, taskID string, now time.Time, limit int) bool { |
| 44 | if l == nil || limit <= 0 { |
| 45 | return true |
| 46 | } |
| 47 | key := string(actor.Kind.Normalize()) + ":" + strings.TrimSpace(actor.Ref) + ":" + strings.TrimSpace(taskID) |
| 48 | l.mu.Lock() |
| 49 | defer l.mu.Unlock() |
| 50 | |
| 51 | window := l.windows[key] |
| 52 | if window.start.IsZero() || now.Sub(window.start) >= time.Minute { |
| 53 | l.windows[key] = forceRunRateWindow{start: now, count: 1} |
| 54 | return true |
| 55 | } |
| 56 | if window.count >= limit { |
| 57 | return false |
| 58 | } |
| 59 | window.count++ |
| 60 | l.windows[key] = window |
| 61 | return true |
| 62 | } |
| 63 | |
| 64 | // ForceReleaseRun releases one claimed run without requiring the raw claim token. |
| 65 | func (m *Service) ForceReleaseRun( |
no test coverage detected