Skip to content

Commit

Permalink
DEV-4783
Browse files Browse the repository at this point in the history
  • Loading branch information
i.navrotskyj committed Dec 10, 2024
1 parent 74ac49c commit ec010b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
18 changes: 13 additions & 5 deletions app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@ func (app *App) SetAgentBreakOut(agent agent_manager.AgentObject) *model.AppErro

func (app *App) hangupNoAnswerChannels(chs []*model.CallNoAnswer) {
for _, ch := range chs {
if err := app.callManager.HangupById(ch.Id, ch.AppId); err != nil {
app.Log.Error(err.Error(),
wlog.Err(err),
wlog.String("call_id", ch.Id),
)
if ch.Id != nil && ch.AppId != nil {
if err := app.callManager.HangupById(*ch.Id, *ch.AppId); err != nil {
app.Log.Error(err.Error(),
wlog.Err(err),
wlog.String("call_id", *ch.Id),
)
}
} else {
// low cps race call DEV-4783
att, ok := app.Queue().Manager().GetAttempt(ch.AttemptId)
if ok {
att.SetCancel()
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions model/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ type CallActionHangup struct {
}

type CallNoAnswer struct {
Id string `json:"id" db:"id"`
AppId string `json:"app_id" db:"app_id"`
Id *string `json:"id" db:"id"`
AppId *string `json:"app_id" db:"app_id"`
AttemptId int64 `json:"attempt_id" db:"attempt_id"`
}

type AmdAiResult struct {
Expand Down
8 changes: 8 additions & 0 deletions queue/attempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ func (a *Attempt) SetCancel() {
}
}

func (a *Attempt) Canceled() bool {
a.RLock()
c := a.canceled
a.RUnlock()

return c
}

func (a *Attempt) Cancel() <-chan struct{} {
return a.cancel
}
Expand Down
6 changes: 6 additions & 0 deletions queue/call_progressive.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func (queue *ProgressiveCallQueue) run(attempt *Attempt, team *agentTeam, agent
})
}

if attempt.Canceled() {
queue.queueManager.SetAttemptAbandonedWithParams(attempt, queue.MaxAttempts+1, 0, nil)
queue.queueManager.LeavingMember(attempt)
return
}

//FIXME update member call id
team.Distribute(queue, agent, NewDistributeEvent(attempt, agent.UserId(), queue, agent, queue.Processing(), nil, mCall))
attempt.memberChannel = mCall
Expand Down
10 changes: 6 additions & 4 deletions store/sqlstore/agent_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,17 @@ WHERE (q_1.team_id IS NULL OR a_1.team_id = q_1.team_id)

func (s *SqlAgentStore) GetNoAnswerChannels(agentId int, queueTypes []int) ([]*model.CallNoAnswer, *model.AppError) {
var res []*model.CallNoAnswer
_, err := s.GetMaster().Select(&res, `select c.id, c.app_id
_, err := s.GetMaster().Select(&res, `select c.id, c.app_id, at.id attempt_id
from call_center.cc_member_attempt at
left join call_center.cc_queue q on q.id = at.queue_id
left join call_center.cc_calls c
on case when q.type = 4 then c.id::text = at.member_call_id else c.id::text = at.agent_call_id end
and c.answered_at isnull
and c.id notnull
where at.agent_id = :AgentId
and c.answered_at isnull
and c.id notnull
and (:QueueTypes::smallint[] isnull or q.type = any(:QueueTypes::smallint[]))`, map[string]interface{}{
and at.channel = 'call'
and at.state = 'offering'
and (:QueueTypes::smallint[] isnull or q.type = any (:QueueTypes::smallint[]))`, map[string]interface{}{
"AgentId": agentId,
"QueueTypes": pq.Array(queueTypes),
})
Expand Down

0 comments on commit ec010b6

Please sign in to comment.