Skip to content

Commit

Permalink
WPRO-942
Browse files Browse the repository at this point in the history
  • Loading branch information
navrotskyj committed Feb 26, 2024
1 parent 48f5726 commit 6e28b50
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions queue/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/webitel/call_center/utils"
"github.com/webitel/protos/workflow"
"github.com/webitel/wlog"
"golang.org/x/sync/singleflight"
"net/http"
"sync"
)

Expand All @@ -17,6 +19,10 @@ const (
MAX_TEAM_EXPIRE_CACHE = 60 * 60 * 24
)

var (
teamGroupRequest singleflight.Group
)

type teamManager struct {
store store.Store
cache utils.ObjectCache
Expand Down Expand Up @@ -85,7 +91,6 @@ func (tm *teamManager) GetTeam(id int, updatedAt int64) (*agentTeam, *model.AppE
defer tm.Unlock()

var team *agentTeam
var err *model.AppError

if t, ok := tm.cache.Get(id); ok {
team = t.(*agentTeam)
Expand All @@ -94,15 +99,31 @@ func (tm *teamManager) GetTeam(id int, updatedAt int64) (*agentTeam, *model.AppE
}
}

data, err := tm.store.Team().Get(id)
v, err, shared := teamGroupRequest.Do(fmt.Sprintf("%d-%d", id, updatedAt), func() (interface{}, error) {
data, err := tm.store.Team().Get(id)
if err != nil {
return nil, err
}

return NewTeam(data, tm), nil
})

if err != nil {
return nil, err
switch err.(type) {
case *model.AppError:
return nil, err.(*model.AppError)
default:
return nil, model.NewAppError("Queue", "queue.manager.team.get", nil, err.Error(), http.StatusInternalServerError)
}
}
team = v.(*agentTeam)

if !shared {
tm.cache.AddWithDefaultExpires(id, team)
wlog.Debug(fmt.Sprintf("team [%d] %v store to cache", team.Id(), team.Name()))
}
team = NewTeam(data, tm)

tm.cache.AddWithDefaultExpires(id, team)
wlog.Debug(fmt.Sprintf("team [%d] %v store to cache", team.Id(), team.Name()))
return team, err
return team, nil
}

func (tm *teamManager) HookAgent(event string, agent agent_manager.AgentObject) *model.AppError {
Expand Down

0 comments on commit 6e28b50

Please sign in to comment.