From 4e16d16395ccb2f1fde0ae501321ad1c6802a89d Mon Sep 17 00:00:00 2001 From: "i.navrotskyj" Date: Tue, 10 Dec 2024 11:52:46 +0200 Subject: [PATCH 1/2] DEV-4783 --- app/agent.go | 18 +++++++++++++----- model/call.go | 5 +++-- queue/attempt.go | 8 ++++++++ queue/call_progressive.go | 6 ++++++ store/sqlstore/agent_store.go | 10 ++++++---- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/app/agent.go b/app/agent.go index 384a9659..8e90bedc 100644 --- a/app/agent.go +++ b/app/agent.go @@ -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() + } } } } diff --git a/model/call.go b/model/call.go index 2375ea71..9df6155f 100644 --- a/model/call.go +++ b/model/call.go @@ -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 { diff --git a/queue/attempt.go b/queue/attempt.go index 4323e493..6f056ff8 100644 --- a/queue/attempt.go +++ b/queue/attempt.go @@ -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 } diff --git a/queue/call_progressive.go b/queue/call_progressive.go index 1d455cae..a7e1bfd5 100644 --- a/queue/call_progressive.go +++ b/queue/call_progressive.go @@ -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 diff --git a/store/sqlstore/agent_store.go b/store/sqlstore/agent_store.go index 2bb2b41f..6ec479b6 100644 --- a/store/sqlstore/agent_store.go +++ b/store/sqlstore/agent_store.go @@ -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), }) From 86ef87b907461da57a142717e5d1a9f36f1834fb Mon Sep 17 00:00:00 2001 From: "i.navrotskyj" Date: Thu, 12 Dec 2024 13:37:30 +0200 Subject: [PATCH 2/2] log_console --- app/config.go | 4 ++++ model/config.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/config.go b/app/config.go index ae5c007e..f81b01b8 100644 --- a/app/config.go +++ b/app/config.go @@ -36,5 +36,9 @@ func loadConfig() (*model.Config, error) { //return nil, err } + if !config.Log.Console && !config.Log.Otel && len(config.Log.File) == 0 { + config.Log.Console = true + } + return &config, nil } diff --git a/model/config.go b/model/config.go index 56e3b6db..f5c138a6 100644 --- a/model/config.go +++ b/model/config.go @@ -17,7 +17,7 @@ type LogSettings struct { Json bool `json:"json" flag:"log_json|false|Log format JSON" env:"LOG_JSON"` Otel bool `json:"otel" flag:"log_otel|false|Log OTEL" env:"LOG_OTEL"` File string `json:"file" flag:"log_file||Log file directory" env:"LOG_FILE"` - Console bool `json:"console" flag:"log_console|1|Log console" env:"LOG_CONSOLE"` + Console bool `json:"console" flag:"log_console|false|Log console" env:"LOG_CONSOLE"` } type CallSettings struct {