fix review changes
This commit is contained in:
@@ -8,15 +8,9 @@ class AutoAssignment::AssignmentJob < ApplicationJob
|
||||
service = AutoAssignment::AssignmentService.new(inbox: inbox)
|
||||
|
||||
assigned_count = service.perform_bulk_assignment(limit: bulk_assignment_limit)
|
||||
success_message = I18n.t('jobs.auto_assignment.assignment_job.bulk_assignment_success',
|
||||
assigned_count: assigned_count,
|
||||
inbox_id: inbox.id)
|
||||
Rails.logger.info success_message
|
||||
Rails.logger.info "Assigned #{assigned_count} conversations for inbox #{inbox.id}"
|
||||
rescue StandardError => e
|
||||
error_message = I18n.t('jobs.auto_assignment.assignment_job.bulk_assignment_failed',
|
||||
inbox_id: inbox.id,
|
||||
error_message: e.message)
|
||||
Rails.logger.error error_message
|
||||
Rails.logger.error "Bulk assignment failed for inbox #{inbox_id}: #{e.message}"
|
||||
raise e if Rails.env.test?
|
||||
end
|
||||
|
||||
|
||||
@@ -2,13 +2,17 @@ class AutoAssignment::PeriodicAssignmentJob < ApplicationJob
|
||||
queue_as :scheduled_jobs
|
||||
|
||||
def perform
|
||||
Account.find_each do |account|
|
||||
next unless account.feature_enabled?('assignment_v2')
|
||||
Account.find_in_batches do |accounts|
|
||||
accounts.each do |account|
|
||||
next unless account.feature_enabled?('assignment_v2')
|
||||
|
||||
account.inboxes.joins(:assignment_policy).find_each do |inbox|
|
||||
next unless inbox.auto_assignment_enabled?
|
||||
account.inboxes.joins(:assignment_policy).find_in_batches do |inboxes|
|
||||
inboxes.each do |inbox|
|
||||
next unless inbox.auto_assignment_v2_enabled?
|
||||
|
||||
AutoAssignment::AssignmentJob.perform_later(inbox_id: inbox.id)
|
||||
AutoAssignment::AssignmentJob.perform_later(inbox_id: inbox.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ module AutoAssignmentHandler
|
||||
return unless conversation_status_changed_to_open?
|
||||
return unless should_run_auto_assignment?
|
||||
|
||||
if inbox.auto_assignment_enabled?
|
||||
if inbox.auto_assignment_v2_enabled?
|
||||
# Use new assignment system
|
||||
AutoAssignment::AssignmentJob.perform_later(inbox_id: inbox.id)
|
||||
else
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ class Inbox < ApplicationRecord
|
||||
members.ids
|
||||
end
|
||||
|
||||
def auto_assignment_enabled?
|
||||
def auto_assignment_v2_enabled?
|
||||
account.feature_enabled?('assignment_v2') && assignment_policy.present? && assignment_policy.enabled?
|
||||
end
|
||||
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
class AutoAssignment::AssignmentService
|
||||
pattr_initialize [:inbox!]
|
||||
|
||||
def perform_for_conversation(conversation)
|
||||
return false unless assignable?(conversation)
|
||||
|
||||
agent = find_available_agent
|
||||
return false unless agent
|
||||
|
||||
assign_conversation(conversation, agent)
|
||||
end
|
||||
|
||||
def perform_bulk_assignment(limit: 100)
|
||||
return 0 unless inbox.enable_auto_assignment?
|
||||
|
||||
@@ -24,27 +15,30 @@ class AutoAssignment::AssignmentService
|
||||
|
||||
private
|
||||
|
||||
def perform_for_conversation(conversation)
|
||||
return false unless assignable?(conversation)
|
||||
|
||||
agent = find_available_agent
|
||||
return false unless agent
|
||||
|
||||
assign_conversation(conversation, agent)
|
||||
end
|
||||
|
||||
def assignable?(conversation)
|
||||
inbox.enable_auto_assignment? &&
|
||||
conversation.status == 'open' &&
|
||||
conversation.status == 'open' &&
|
||||
conversation.assignee_id.nil?
|
||||
end
|
||||
|
||||
def unassigned_conversations(limit)
|
||||
scope = inbox.conversations.unassigned.open
|
||||
|
||||
# Apply conversation priority from config
|
||||
scope = apply_conversation_priority(scope)
|
||||
scope.limit(limit)
|
||||
end
|
||||
|
||||
def apply_conversation_priority(scope)
|
||||
case assignment_config['conversation_priority']
|
||||
when 'longest_waiting'
|
||||
scope.order(last_activity_at: :asc, created_at: :asc)
|
||||
if assignment_config['conversation_priority'] == 'longest_waiting'
|
||||
scope = scope.order(last_activity_at: :asc, created_at: :asc)
|
||||
else
|
||||
scope.order(created_at: :asc)
|
||||
end
|
||||
|
||||
scope.limit(limit)
|
||||
end
|
||||
|
||||
def find_available_agent
|
||||
@@ -69,9 +63,6 @@ class AutoAssignment::AssignmentService
|
||||
|
||||
dispatch_assignment_event(conversation, agent)
|
||||
true
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
Rails.logger.error "AutoAssignment failed for conversation #{conversation.id}: #{e.message}"
|
||||
false
|
||||
end
|
||||
|
||||
def dispatch_assignment_event(conversation, agent)
|
||||
|
||||
+4
-4
@@ -194,12 +194,12 @@
|
||||
- name: twilio_content_templates
|
||||
display_name: Twilio Content Templates
|
||||
enabled: false
|
||||
- name: assignment_v2
|
||||
display_name: Assignment V2
|
||||
enabled: false
|
||||
chatwoot_internal: true
|
||||
- name: advanced_search
|
||||
display_name: Advanced Search
|
||||
enabled: false
|
||||
premium: true
|
||||
chatwoot_internal: true
|
||||
- name: assignment_v2
|
||||
display_name: Assignment V2
|
||||
enabled: false
|
||||
chatwoot_internal: true
|
||||
|
||||
@@ -394,11 +394,6 @@ en:
|
||||
%{format_messages}
|
||||
agent_capacity_policy:
|
||||
inbox_already_assigned: 'Inbox has already been assigned to this policy'
|
||||
jobs:
|
||||
auto_assignment:
|
||||
assignment_job:
|
||||
bulk_assignment_success: 'Assigned %{assigned_count} conversations for inbox %{inbox_id}'
|
||||
bulk_assignment_failed: 'Bulk assignment failed for inbox %{inbox_id}: %{error_message}'
|
||||
portals:
|
||||
send_instructions:
|
||||
email_required: 'Email is required'
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
module Enterprise::AssignmentPolicy
|
||||
def assignment_order=(value)
|
||||
if value.to_s == 'balanced'
|
||||
write_attribute(:assignment_order, 1)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def assignment_order
|
||||
value = read_attribute(:assignment_order)
|
||||
return 'balanced' if value == 1
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def balanced?
|
||||
self[:assignment_order] == 1
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user