Chore: Refactor round robin logic (#1015)
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
@@ -188,7 +188,7 @@ class Conversation < ApplicationRecord
|
||||
return unless conversation_status_changed_to_open?
|
||||
return unless should_round_robin?
|
||||
|
||||
inbox.next_available_agent.then { |new_assignee| update_assignee(new_assignee) }
|
||||
::RoundRobin::AssignmentService.new(conversation: self).perform
|
||||
end
|
||||
|
||||
def create_status_change_message(user_name)
|
||||
|
||||
@@ -64,11 +64,6 @@ class Inbox < ApplicationRecord
|
||||
channel.class.name.to_s == 'Channel::WebWidget'
|
||||
end
|
||||
|
||||
def next_available_agent
|
||||
user_id = Redis::Alfred.rpoplpush(round_robin_key, round_robin_key)
|
||||
account.users.find_by(id: user_id)
|
||||
end
|
||||
|
||||
def webhook_data
|
||||
{
|
||||
id: id,
|
||||
@@ -79,10 +74,6 @@ class Inbox < ApplicationRecord
|
||||
private
|
||||
|
||||
def delete_round_robin_agents
|
||||
Redis::Alfred.delete(round_robin_key)
|
||||
end
|
||||
|
||||
def round_robin_key
|
||||
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: id)
|
||||
::RoundRobin::ManageService.new(inbox: self).clear_queue
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,14 +26,10 @@ class InboxMember < ApplicationRecord
|
||||
private
|
||||
|
||||
def add_agent_to_round_robin
|
||||
Redis::Alfred.lpush(round_robin_key, user_id)
|
||||
::RoundRobin::ManageService.new(inbox: inbox).add_agent_to_queue(user_id)
|
||||
end
|
||||
|
||||
def remove_agent_from_round_robin
|
||||
Redis::Alfred.lrem(round_robin_key, user_id)
|
||||
end
|
||||
|
||||
def round_robin_key
|
||||
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: inbox_id)
|
||||
::RoundRobin::ManageService.new(inbox: inbox).remove_agent_from_queue(user_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -153,7 +153,6 @@ class Message < ApplicationRecord
|
||||
end
|
||||
|
||||
def notify_via_mail
|
||||
conversation_mail_key = Redis::Alfred::CONVERSATION_MAILER_KEY % conversation.id
|
||||
if Redis::Alfred.get(conversation_mail_key).nil? && conversation.contact.email? && outgoing?
|
||||
# set a redis key for the conversation so that we don't need to send email for every
|
||||
# new message that comes in and we dont enque the delayed sidekiq job for every message
|
||||
@@ -165,6 +164,10 @@ class Message < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def conversation_mail_key
|
||||
format(::Redis::Alfred::CONVERSATION_MAILER_KEY, conversation_id: conversation.id)
|
||||
end
|
||||
|
||||
def validate_attachments_limit(_attachment)
|
||||
errors.add(attachments: 'exceeded maximum allowed') if attachments.size >= NUMBER_OF_PERMITTED_ATTACHMENTS
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user