Skip to content

Commit

Permalink
WTEL-4679
Browse files Browse the repository at this point in the history
  • Loading branch information
i.navrotskyj committed Jun 27, 2024
1 parent c6fa293 commit 3fc48c8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
24 changes: 18 additions & 6 deletions agent_manager/agent_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ var (
MaxAgentOnlineWithOutSocSec = 60
)

type HookAutoOfflineAgent func(agent AgentObject)

type agentManager struct {
store store.Store
mq mq.MQ
watcher *utils.Watcher
nodeId string
startOnce sync.Once
agentsCache utils.ObjectCache
store store.Store
mq mq.MQ
watcher *utils.Watcher
nodeId string
startOnce sync.Once
agentsCache utils.ObjectCache
hookAutoOfflineAgent HookAutoOfflineAgent
sync.Mutex
}

Expand All @@ -41,6 +44,10 @@ func NewAgentManager(nodeId string, s store.Store, mq_ mq.MQ) AgentManager {
return &am
}

func (am *agentManager) SetHookAutoOfflineAgent(hook HookAutoOfflineAgent) {
am.hookAutoOfflineAgent = hook
}

func (am *agentManager) Start() {
wlog.Debug("starting agent service")
am.watcher = utils.MakeWatcher("AgentManager", watcherPollingInterval, am.changeDeadlineState)
Expand Down Expand Up @@ -193,9 +200,14 @@ func (am *agentManager) changeDeadlineState() {
*s = *s + "/sip"
}
}
if a.TeamUpdatedAt() != v.TeamUpdatedAt {
a.SetTeamUpdatedAt(v.TeamUpdatedAt)
}
err = am.SetOffline(a, s)
if err != nil {
wlog.Error(err.Error())
} else if am.hookAutoOfflineAgent != nil {
am.hookAutoOfflineAgent(a)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions agent_manager/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type AgentManager interface {
//internal
SetAgentOnBreak(agentId int) *model.AppError
MissedAttempt(agentId int, attemptId int64, cause string) *model.AppError
SetHookAutoOfflineAgent(hook HookAutoOfflineAgent)
}

type AgentObject interface {
Expand Down
5 changes: 5 additions & 0 deletions app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (app *App) RunTeamTrigger(ctx context.Context, domainId int64, userId int64
return jobId, nil
}

func (app *App) hookAutoOfflineAgent(agent agent_manager.AgentObject) {
app.Queue().Manager().AgentTeamHook(model.HookAgentStatus, agent, agent.TeamUpdatedAt())
return
}

func getString(p *string) string {
if p == nil {
return ""
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func New(options ...string) (outApp *App, outErr error) {
app.engine.Start()

app.agentManager = agent_manager.NewAgentManager(app.GetInstanceId(), app.Store, app.MQ)
app.agentManager.SetHookAutoOfflineAgent(app.hookAutoOfflineAgent)
app.agentManager.Start()

app.flowManager = client.NewFlowManager(app.Cluster().ServiceDiscovery())
Expand Down
9 changes: 5 additions & 4 deletions model/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ type Agent struct {
}

type AgentHashKey struct {
Id int `json:"id" db:"id" `
UpdatedAt int64 `json:"updated_at" db:"updated_at"`
Sip bool `json:"sip" db:"sip"`
Ws bool `json:"ws" db:"ws"`
Id int `json:"id" db:"id" `
UpdatedAt int64 `json:"updated_at" db:"updated_at"`
Sip bool `json:"sip" db:"sip"`
Ws bool `json:"ws" db:"ws"`
TeamUpdatedAt int64 `json:"team_updated_at" db:"team_updated_at"`
}

type AgentChannel struct {
Expand Down
6 changes: 4 additions & 2 deletions store/sqlstore/agent_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ func (s *SqlAgentStore) OnlineWithOutActive(sec int) ([]model.AgentHashKey, *mod
where p.user_id = a.user_id
and p.status = 'web'
and p.updated_at >= now() at time zone 'UTC' - (:Sec || ' sec')::interval
) ws
) ws,
t.updated_at as team_updated_at
from call_center.cc_agent a
left join call_center.cc_team t on t.id = a.team_id
where a.status in ('online', 'break_out')
and not exists(SELECT 1
FROM directory.wbt_session s
Expand All @@ -371,7 +373,7 @@ where a.status in ('online', 'break_out')
or (p.status = 'web' and p.updated_at >= now() at time zone 'UTC' - (:Sec || ' sec')::interval)
)
)
for update skip locked`, map[string]interface{}{
for update of a skip locked`, map[string]interface{}{
"Sec": sec,
})

Expand Down

0 comments on commit 3fc48c8

Please sign in to comment.