temp_unsched.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // TempUnschedState 临时不可调度状态
  7. type TempUnschedState struct {
  8. UntilUnix int64 `json:"until_unix"` // 解除时间(Unix 时间戳)
  9. TriggeredAtUnix int64 `json:"triggered_at_unix"` // 触发时间(Unix 时间戳)
  10. StatusCode int `json:"status_code"` // 触发的错误码
  11. MatchedKeyword string `json:"matched_keyword"` // 匹配的关键词
  12. RuleIndex int `json:"rule_index"` // 触发的规则索引
  13. ErrorMessage string `json:"error_message"` // 错误消息
  14. TriggerCount int64 `json:"trigger_count,omitempty"` // 本次触发累计命中次数
  15. TriggerThreshold int `json:"trigger_threshold,omitempty"` // 触发阈值
  16. TriggerWindowMinutes int `json:"trigger_window_minutes,omitempty"` // 计数窗口(分钟)
  17. }
  18. // TempUnschedCache 临时不可调度缓存接口
  19. type TempUnschedCache interface {
  20. SetTempUnsched(ctx context.Context, accountID int64, state *TempUnschedState) error
  21. GetTempUnsched(ctx context.Context, accountID int64) (*TempUnschedState, error)
  22. DeleteTempUnsched(ctx context.Context, accountID int64) error
  23. }
  24. // OpenAIAPIKeyHealthCache is an optional TempUnschedCache extension used to
  25. // aggregate pool API-key failures across gateway instances.
  26. type OpenAIAPIKeyHealthCache interface {
  27. RecordOpenAIAPIKeyHealthFailure(ctx context.Context, accountID int64, windowMinutes, threshold int) (count int64, tripped bool, err error)
  28. }
  29. // TimeoutCounterCache 超时计数器缓存接口
  30. type TimeoutCounterCache interface {
  31. // IncrementTimeoutCount 增加账户的超时计数,返回当前计数值
  32. // windowMinutes 是计数窗口时间(分钟),超过此时间计数器会自动重置
  33. IncrementTimeoutCount(ctx context.Context, accountID int64, windowMinutes int) (int64, error)
  34. // GetTimeoutCount 获取账户当前的超时计数
  35. GetTimeoutCount(ctx context.Context, accountID int64) (int64, error)
  36. // ResetTimeoutCount 重置账户的超时计数
  37. ResetTimeoutCount(ctx context.Context, accountID int64) error
  38. // GetTimeoutCountTTL 获取计数器剩余过期时间
  39. GetTimeoutCountTTL(ctx context.Context, accountID int64) (time.Duration, error)
  40. }