chore: Limit conversation resolution Job (#6433)
We will be adding a limit to the resolution job so that it is performed at a spaced interval. This will ensure there won't be a sudden spike in resource usage fixes: chatwoot/product#707
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
class Conversations::ResolutionJob < ApplicationJob
|
||||
queue_as :medium
|
||||
queue_as :low
|
||||
|
||||
def perform(account:)
|
||||
resolvable_conversations = account.conversations.resolvable(account.auto_resolve_duration)
|
||||
# limiting the number of conversations to be resolved to avoid any performance issues
|
||||
resolvable_conversations = account.conversations.resolvable(account.auto_resolve_duration).limit(Limits::BULK_ACTIONS_LIMIT)
|
||||
resolvable_conversations.each(&:toggle_status)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,7 +63,7 @@ class Conversation < ApplicationRecord
|
||||
scope :assigned, -> { where.not(assignee_id: nil) }
|
||||
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
|
||||
scope :resolvable, lambda { |auto_resolve_duration|
|
||||
return [] if auto_resolve_duration.to_i.zero?
|
||||
return none if auto_resolve_duration.to_i.zero?
|
||||
|
||||
open.where('last_activity_at < ? ', Time.now.utc - auto_resolve_duration.days)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user