Documentation
¶
Index ¶
- type Assignment
- type Broker
- type Config
- type DistributionStrategy
- type Lead
- type MLOptimizedStrategy
- type PerformanceBasedStrategy
- type PriorityQueue
- type Queue
- func (q *Queue) Clear()
- func (q *Queue) Dequeue() (*Lead, error)
- func (q *Queue) Enqueue(lead *Lead) error
- func (q *Queue) GetLeadsByPriority() map[int][]*Lead
- func (q *Queue) GetMetrics() *QueueMetrics
- func (q *Queue) GetQueueSnapshot() *QueueSnapshot
- func (q *Queue) GetWaitTimes() []time.Duration
- func (q *Queue) IsEmpty() bool
- func (q *Queue) IsFull() bool
- func (q *Queue) Peek() (*Lead, error)
- func (q *Queue) RemoveLead(leadID string) (*Lead, error)
- func (q *Queue) Size() int
- func (q *Queue) UpdatePriority(leadID string, newPriority int) error
- type QueueItem
- type QueueMetrics
- type QueueSnapshot
- type RegionalStrategy
- type RoundRobinStrategy
- type Service
- func (s *Service) AssignLead(ctx context.Context, leadID, brokerID string, force bool) (*Assignment, error)
- func (s *Service) DistributeLead(ctx context.Context, lead *Lead) error
- func (s *Service) GetQueueStats() map[string]interface{}
- func (s *Service) IsReady() bool
- func (s *Service) Rebalance(ctx context.Context, strategy string, params map[string]interface{}) error
- func (s *Service) StartQueueProcessor(ctx context.Context)
- type SpecialtyBasedStrategy
- type Strategy
- type StrategySelector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assignment ¶
type Assignment struct { LeadID string `json:"lead_id"` BrokerID string `json:"broker_id"` TenantID string `json:"tenant_id"` Strategy Strategy `json:"strategy"` Score float64 `json:"score"` Reason string `json:"reason"` AssignedAt time.Time `json:"assigned_at"` Lead *Lead `json:"lead,omitempty"` Broker *Broker `json:"broker,omitempty"` }
Assignment represents a lead-broker assignment
type Broker ¶
type Broker struct { ID string `json:"id"` TenantID string `json:"tenant_id"` Name string `json:"name"` Status string `json:"status"` Capacity int `json:"capacity"` CurrentLoad int `json:"current_load"` Performance float64 `json:"performance_score"` Specialties []string `json:"specialties"` Regions []string `json:"regions"` Tier string `json:"tier"` LastActiveAt time.Time `json:"last_active_at"` Availability bool `json:"availability"` }
Broker represents a broker in the distribution system
type Config ¶
type Config struct { DefaultStrategy Strategy MaxQueueSize int MaxWaitTime time.Duration Enabled bool }
Config holds distribution service configuration
type DistributionStrategy ¶
type DistributionStrategy interface { Name() Strategy Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error) Priority() int Enabled() bool }
DistributionStrategy interface for different assignment strategies
type Lead ¶
type Lead struct { ID string `json:"id"` TenantID string `json:"tenant_id"` Name string `json:"name"` Email string `json:"email"` Phone string `json:"phone"` Source string `json:"source"` Priority int `json:"priority"` Score int `json:"score"` Properties map[string]interface{} `json:"properties"` Tags []string `json:"tags"` CreatedAt time.Time `json:"created_at"` Region string `json:"region"` Urgency string `json:"urgency"` Budget float64 `json:"budget"` Interests []string `json:"interests"` }
Lead represents a lead to be distributed
type MLOptimizedStrategy ¶
type MLOptimizedStrategy struct {
// contains filtered or unexported fields
}
MLOptimizedStrategy uses machine learning to optimize assignments
func (*MLOptimizedStrategy) Assign ¶
func (s *MLOptimizedStrategy) Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error)
func (*MLOptimizedStrategy) Enabled ¶
func (s *MLOptimizedStrategy) Enabled() bool
func (*MLOptimizedStrategy) Name ¶
func (s *MLOptimizedStrategy) Name() Strategy
func (*MLOptimizedStrategy) Priority ¶
func (s *MLOptimizedStrategy) Priority() int
type PerformanceBasedStrategy ¶
type PerformanceBasedStrategy struct{}
PerformanceBasedStrategy assigns leads based on broker performance scores
func (*PerformanceBasedStrategy) Assign ¶
func (s *PerformanceBasedStrategy) Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error)
func (*PerformanceBasedStrategy) Enabled ¶
func (s *PerformanceBasedStrategy) Enabled() bool
func (*PerformanceBasedStrategy) Name ¶
func (s *PerformanceBasedStrategy) Name() Strategy
func (*PerformanceBasedStrategy) Priority ¶
func (s *PerformanceBasedStrategy) Priority() int
type PriorityQueue ¶
type PriorityQueue []*QueueItem
PriorityQueue implements heap.Interface for lead prioritization
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue manages the lead distribution queue with priority support
func (*Queue) GetLeadsByPriority ¶
GetLeadsByPriority returns all leads grouped by priority level
func (*Queue) GetMetrics ¶
func (q *Queue) GetMetrics() *QueueMetrics
GetMetrics returns queue performance metrics
func (*Queue) GetQueueSnapshot ¶
func (q *Queue) GetQueueSnapshot() *QueueSnapshot
GetQueueSnapshot returns a snapshot of the current queue state
func (*Queue) GetWaitTimes ¶
GetWaitTimes returns wait times for all leads currently in queue
func (*Queue) RemoveLead ¶
RemoveLead removes a specific lead from the queue (for cancellations)
type QueueMetrics ¶
type QueueMetrics struct { TotalEnqueued int64 TotalDequeued int64 TotalRejected int64 AverageWaitTime time.Duration PeakSize int CreatedAt time.Time }
QueueMetrics tracks queue performance metrics
type QueueSnapshot ¶
type QueueSnapshot struct { Size int `json:"size"` MaxSize int `json:"max_size"` Utilization float64 `json:"utilization"` Metrics *QueueMetrics `json:"metrics"` LeadsByPriority map[int]int `json:"leads_by_priority"` AverageWaitTime time.Duration `json:"average_wait_time"` OldestLeadAge time.Duration `json:"oldest_lead_age"` }
QueueSnapshot represents a point-in-time view of the queue
type RegionalStrategy ¶
type RegionalStrategy struct{}
RegionalStrategy assigns leads based on geographical proximity
func (*RegionalStrategy) Assign ¶
func (s *RegionalStrategy) Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error)
func (*RegionalStrategy) Enabled ¶
func (s *RegionalStrategy) Enabled() bool
func (*RegionalStrategy) Name ¶
func (s *RegionalStrategy) Name() Strategy
func (*RegionalStrategy) Priority ¶
func (s *RegionalStrategy) Priority() int
type RoundRobinStrategy ¶
type RoundRobinStrategy struct {
// contains filtered or unexported fields
}
RoundRobinStrategy distributes leads evenly across available brokers
func (*RoundRobinStrategy) Assign ¶
func (s *RoundRobinStrategy) Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error)
func (*RoundRobinStrategy) Enabled ¶
func (s *RoundRobinStrategy) Enabled() bool
func (*RoundRobinStrategy) Name ¶
func (s *RoundRobinStrategy) Name() Strategy
func (*RoundRobinStrategy) Priority ¶
func (s *RoundRobinStrategy) Priority() int
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles lead distribution logic
func NewService ¶
func NewService(config *Config, mlSvc *ml.Service, slaManager *sla.Manager, antiAbuse *antiabuse.Service, eventBus *events.Bus) (*Service, error)
NewService creates a new distribution service
func (*Service) AssignLead ¶
func (s *Service) AssignLead(ctx context.Context, leadID, brokerID string, force bool) (*Assignment, error)
AssignLead manually assigns a lead to a broker
func (*Service) DistributeLead ¶
DistributeLead adds a lead to the distribution queue
func (*Service) GetQueueStats ¶
GetQueueStats returns current queue statistics
func (*Service) Rebalance ¶
func (s *Service) Rebalance(ctx context.Context, strategy string, params map[string]interface{}) error
Rebalance triggers queue rebalancing
func (*Service) StartQueueProcessor ¶
StartQueueProcessor starts the background queue processing
type SpecialtyBasedStrategy ¶
type SpecialtyBasedStrategy struct{}
SpecialtyBasedStrategy matches leads with brokers based on specializations
func (*SpecialtyBasedStrategy) Assign ¶
func (s *SpecialtyBasedStrategy) Assign(ctx context.Context, lead *Lead, brokers []*Broker) (*Assignment, error)
func (*SpecialtyBasedStrategy) Enabled ¶
func (s *SpecialtyBasedStrategy) Enabled() bool
func (*SpecialtyBasedStrategy) Name ¶
func (s *SpecialtyBasedStrategy) Name() Strategy
func (*SpecialtyBasedStrategy) Priority ¶
func (s *SpecialtyBasedStrategy) Priority() int
type StrategySelector ¶
type StrategySelector struct {
// contains filtered or unexported fields
}
StrategySelector selects the best strategy for a given lead
func NewStrategySelector ¶
func NewStrategySelector(strategies map[Strategy]DistributionStrategy) *StrategySelector
func (*StrategySelector) SelectBestStrategy ¶
func (ss *StrategySelector) SelectBestStrategy(lead *Lead, brokers []*Broker) DistributionStrategy