Skip to content

Commit

Permalink
WTEL-2822
Browse files Browse the repository at this point in the history
  • Loading branch information
navrotskyj committed Sep 22, 2023
1 parent 3625e81 commit 6850784
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 64 deletions.
11 changes: 6 additions & 5 deletions app/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ func (a *App) NotificationInterceptAttempt(domainId int64, queueId int, channel
})
}

func (a *App) NotificationWaitingList(domainId int64, userIds []int64, list []*model.MemberWaiting) *model.AppError {
return a.MQ.SendNotification(domainId, &model.Notification{
func (a *App) NotificationWaitingList(e *model.MemberWaitingByUsers) *model.AppError {
return a.MQ.SendNotification(e.DomainId, &model.Notification{
Id: 0,
DomainId: domainId,
DomainId: e.DomainId,
Action: model.NotificationWaitingList,
CreatedAt: model.GetMillis(),
ForUsers: userIds,
ForUsers: e.Users,
Body: map[string]interface{}{
"list": list,
"calls": e.Calls,
"chats": e.Chats,
},
})
}
5 changes: 3 additions & 2 deletions model/manual_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package model
import "encoding/json"

type MemberWaiting struct {
Position int `json:"position" db:"position"`
AttemptId int64 `json:"attempt_id" db:"attempt_id"`
Wait int `json:"wait" db:"wait"`
Communication json.RawMessage `json:"communication" db:"communication"`
Queue Lookup `json:"queue" db:"queue"`
Bucket *Lookup `json:"bucket,omitempty" db:"bucket"`
Deadline int `json:"deadline" db:"deadline"`
Channel string `json:"channel" db:"channel"`
SessionId string `json:"session_id,omitempty" db:"session_id,omitempty"`
}

type MemberWaitingByUsers struct {
DomainId int64 `json:"-" db:"domain_id"`
Users Int64Array `json:"-" db:"users"`
Members []*MemberWaiting `json:"-" db:"members"`
Calls []*MemberWaiting `json:"-" db:"calls"`
Chats []*MemberWaiting `json:"-" db:"chats"`
}
2 changes: 1 addition & 1 deletion queue/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ type App interface {
QueueSettings() model.QueueSettings
NotificationHideMember(domainId int64, queueId int, memberId *int64, agentId int) *model.AppError
NotificationInterceptAttempt(domainId int64, queueId int, channel string, attemptId int64, skipAgentId int32) *model.AppError
NotificationWaitingList(domainId int64, userIds []int64, list []*model.MemberWaiting) *model.AppError
NotificationWaitingList(e *model.MemberWaitingByUsers) *model.AppError
}
2 changes: 1 addition & 1 deletion queue/queue_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (qm *QueueManager) listWaiting() {
}

for _, v := range list {
err = qm.app.NotificationWaitingList(v.DomainId, v.Users, v.Members)
err = qm.app.NotificationWaitingList(v)
if err != nil {
wlog.Error(err.Error())
}
Expand Down
54 changes: 2 additions & 52 deletions store/sqlstore/member_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,58 +986,8 @@ where id = :Id;`, map[string]interface{}{

func (s *SqlMemberStore) WaitingList() ([]*model.MemberWaitingByUsers, *model.AppError) {
var list []*model.MemberWaitingByUsers
_, err := s.GetMaster().Select(&list, `with queues as materialized (
SELECT q.domain_id,
q.name,
qs.queue_id,
q.priority,
coalesce((q.payload->'max_wait_time')::int, 0) as max_wait_time,
coalesce((q.payload->'sticky_agent_sec')::int, 0) as sticky_agent_sec,
q.sticky_agent,
b as bucket_id,
max(qs.lvl) lvl,
array_agg(distinct csia.agent_id) agents,
array_agg(distinct a.user_id) users
FROM call_center.cc_queue q
join call_center.cc_queue_skill qs on qs.queue_id = q.id
JOIN call_center.cc_skill_in_agent csia ON csia.skill_id = qs.skill_id
join call_center.cc_agent a on a.id = csia.agent_id and (q.team_id isnull or q.team_id = a.team_id)
left join lateral unnest(qs.bucket_ids) b on true
WHERE qs.enabled
AND csia.enabled
AND csia.capacity >= qs.min_capacity
AND csia.capacity <= qs.max_capacity
and q.domain_id = a.domain_id
and a.status = 'online'
and coalesce((q.payload->'manual_distribution')::bool, false)
group by 1, 2, 3, 4, 5, 6, 7, 8
)
select list.domain_id, list.users::int8[] as users, jsonb_agg(row_to_json(list)::jsonb - 'domain_id' - 'users') as members
from (
select row_number()
over (order by q.priority desc, (extract(epoch from now() - coalesce(a.transferred_at, a.joined_at)) +
a.weight) desc) position,
a.id attempt_id,
extract(epoch from now() - joined_at)::int as wait,
a.destination::jsonb as communication,
call_center.cc_get_lookup(q.queue_id, q.name) as queue,
call_center.cc_get_lookup(b.id::int8, b.name::text) as bucket,
((extract(epoch from now() - joined_at)::numeric / q.max_wait_time::numeric) * 100)::int as deadline,
-- q.agents,
q.users,
a.channel,
q.domain_id
from queues q
inner join call_center.cc_member_attempt a on q.queue_id = a.queue_id
left join call_center.cc_bucket b on b.id = a.bucket_id
where a.domain_id = q.domain_id
and a.agent_id isnull
and a.state = 'wait_agent'
and a.queue_id = q.queue_id
and coalesce(q.bucket_id, 0) = coalesce(a.bucket_id, 0)
order by q.lvl, q.priority desc, (extract(epoch from now() - a.joined_at) + a.weight) desc
) list
group by 1, 2`)
_, err := s.GetMaster().Select(&list, `select domain_id, users, chats, calls
from call_center.cc_manual_queue_list`)

if err != nil {
return nil, model.NewAppError("SqlMemberStore.WaitingList", "store.sql_member.waiting_list.app_error", nil,
Expand Down
6 changes: 3 additions & 3 deletions store/sqlstore/supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ func (me typeConverter) ToDb(val interface{}) (interface{}, error) {

func (me typeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool) {
switch target.(type) {
case *model.OutboundResourceParameters:
case *model.OutboundResourceParameters,
*[]*model.MemberWaiting:
binder := func(holder, target interface{}) error {
s, ok := holder.(*[]byte)
if !ok {
Expand All @@ -264,8 +265,7 @@ func (me typeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool) {
case *model.Lookup,
*model.RingtoneFile,
*model.AgentChannel,
*[]model.AgentChannel,
*[]*model.MemberWaiting:
*[]model.AgentChannel:
binder := func(holder, target interface{}) error {
s, ok := holder.(*string)
if !ok {
Expand Down

0 comments on commit 6850784

Please sign in to comment.