* fix(HH-554): connect auto-assignment runtime policy * fix(HH-554): bound and coalesce assignment jobs * fix(HH-554): drain assignment backlog safely * fix(HH-554): hold assignment claim through retries --------- Co-authored-by: Rogee <rogee@ipao.vip>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package autoassignment
|
|
|
|
import "github.com/gochat/gochat/internal/model"
|
|
|
|
// AssignmentPolicyType defines the type of auto-assignment policy.
|
|
type AssignmentPolicyType string
|
|
|
|
const (
|
|
// PolicyRoundRobin assigns conversations to agents in round-robin order.
|
|
// Reference: Chatwoot InboxRoundRobinService
|
|
PolicyRoundRobin AssignmentPolicyType = "round_robin"
|
|
|
|
// PolicyLowestLoad assigns conversations to the agent with the
|
|
// fewest currently open conversations.
|
|
// This implements Chatwoot's balanced assignment order.
|
|
PolicyLowestLoad AssignmentPolicyType = "lowest_load"
|
|
)
|
|
|
|
// EffectivePolicy maps the persisted Chatwoot assignment order to its runtime
|
|
// selector. Balanced assignment remains feature-gated like upstream Chatwoot.
|
|
func EffectivePolicy(policy *model.AssignmentPolicy, advancedAssignment bool) AssignmentPolicyType {
|
|
if policy != nil && policy.AssignmentOrder == 1 && advancedAssignment {
|
|
return PolicyLowestLoad
|
|
}
|
|
return PolicyRoundRobin
|
|
}
|
|
|
|
// EffectiveLimit returns the linked policy's fair-distribution limit.
|
|
func EffectiveLimit(policy *model.AssignmentPolicy) int {
|
|
if policy != nil && policy.FairDistributionLimit > 0 {
|
|
return policy.FairDistributionLimit
|
|
}
|
|
return 5
|
|
}
|
|
|
|
// EffectiveWindow returns the linked policy's rate-limit window in seconds.
|
|
func EffectiveWindow(policy *model.AssignmentPolicy) int {
|
|
if policy != nil && policy.FairDistributionWindow > 0 {
|
|
return policy.FairDistributionWindow
|
|
}
|
|
return 300
|
|
}
|