Documentation
¶
Overview ¶
Package rules provides the notification rule engine for throttling, aggregation, and mute/DND.
Index ¶
- func Init(store *cache.RedisStore) error
- func ValidateCondition(condition string) error
- type AggregateKey
- type Engine
- func (e *Engine) CheckThrottle(ctx context.Context, ruleID, eventType, channel string, window time.Duration, ...) (bool, error)
- func (e *Engine) ClearThrottle(ctx context.Context, ruleID, eventType, channel string)
- func (e *Engine) EnqueueForAggregation(ctx context.Context, ruleID, eventType, channel string, payload map[string]any) error
- func (e *Engine) Evaluate(_ context.Context, eventType, channel string) *EvalResult
- func (e *Engine) FlushAggregation(ctx context.Context, ruleID, eventType, channel string) ([]map[string]any, error)
- func (e *Engine) LoadConfig(rules []config.NotifyRule) error
- func (e *Engine) Reload(ctx context.Context, loader func(context.Context) ([]config.NotifyRule, error)) error
- func (e *Engine) ScanExpiredAggregates(ctx context.Context) ([]AggregateKey, error)
- func (e *Engine) SetAggregateTimer(ctx context.Context, ruleID, eventType, channel string, window time.Duration) (bool, error)
- type EvalResult
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(store *cache.RedisStore) error
Init initializes the global rule engine with configuration and a RedisStore.
func ValidateCondition ¶
ValidateCondition checks whether a condition expression string is syntactically valid. It uses the same parsing logic as evalCondition but without evaluating time values.
Types ¶
type AggregateKey ¶
AggregateKey holds the parsed components of an aggregate timer key.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine evaluates notification rules to determine whether a message should be sent, throttled, aggregated, or dropped.
func (*Engine) CheckThrottle ¶
func (e *Engine) CheckThrottle(ctx context.Context, ruleID, eventType, channel string, window time.Duration, limit int) (bool, error)
CheckThrottle checks whether a notification is within the rate limit for the given key. Returns true if the notification is allowed, false if it should be dropped.
func (*Engine) ClearThrottle ¶
ClearThrottle removes the throttle counter for a given key, resetting the rate limiter.
func (*Engine) EnqueueForAggregation ¶
func (e *Engine) EnqueueForAggregation(ctx context.Context, ruleID, eventType, channel string, payload map[string]any) error
EnqueueForAggregation adds a payload to the aggregation buffer for later digest delivery.
func (*Engine) Evaluate ¶
func (e *Engine) Evaluate(_ context.Context, eventType, channel string) *EvalResult
Evaluate checks all rules against an event type and channel, returning the first matching action.
func (*Engine) FlushAggregation ¶
func (e *Engine) FlushAggregation(ctx context.Context, ruleID, eventType, channel string) ([]map[string]any, error)
FlushAggregation retrieves all buffered payloads for a given rule/channel and clears the buffer.
func (*Engine) LoadConfig ¶
func (e *Engine) LoadConfig(rules []config.NotifyRule) error
LoadConfig loads and sorts rules from configuration.
func (*Engine) Reload ¶
func (e *Engine) Reload(ctx context.Context, loader func(context.Context) ([]config.NotifyRule, error)) error
Reload refreshes the rule list from the database. Called after rule CRUD operations to enable hot-reload without restart.
func (*Engine) ScanExpiredAggregates ¶
func (e *Engine) ScanExpiredAggregates(ctx context.Context) ([]AggregateKey, error)
ScanExpiredAggregates finds aggregate timer keys that have expired and returns their rule/channel info.
type EvalResult ¶
type EvalResult struct {
Action config.NotifyRuleAction
RuleID string
Window string
Limit int
Muted bool
}
EvalResult represents the outcome of rule evaluation.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker periodically scans for expired aggregation windows and flushes them.