@@ -0,0 +1,9 @@
|
||||
class Account::ConversationsResolutionSchedulerJob < ApplicationJob
|
||||
queue_as :scheduled_jobs
|
||||
|
||||
def perform
|
||||
Account.where.not(auto_resolve_duration: nil).all.each do |account|
|
||||
Conversations::ResolutionJob.perform_later(account: account)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
class AutoResolveConversationsJob < ApplicationJob
|
||||
queue_as :medium
|
||||
|
||||
def perform(conversation_id)
|
||||
conversation = Conversation.find_by(id: conversation_id)
|
||||
return unless conversation&.auto_resolve_duration && conversation&.open?
|
||||
|
||||
time_since_last_activity = Time.zone.now.to_i - conversation.last_activity_at.to_i
|
||||
time_left_to_auto_resolve = conversation.auto_resolve_duration.days.to_i - time_since_last_activity
|
||||
if time_left_to_auto_resolve.positive?
|
||||
AutoResolveConversationsJob.set(wait_until: time_left_to_auto_resolve.seconds.from_now).perform_later(conversation_id)
|
||||
else
|
||||
conversation.toggle_status
|
||||
end
|
||||
end
|
||||
end
|
||||
8
app/jobs/conversations/resolution_job.rb
Normal file
8
app/jobs/conversations/resolution_job.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Conversations::ResolutionJob < ApplicationJob
|
||||
queue_as :medium
|
||||
|
||||
def perform(account:)
|
||||
resolvable_conversations = account.conversations.resolvable(account.auto_resolve_duration)
|
||||
resolvable_conversations.each(&:toggle_status)
|
||||
end
|
||||
end
|
||||
@@ -9,5 +9,8 @@ class TriggerScheduledItemsJob < ApplicationJob
|
||||
|
||||
# Job to reopen snoozed conversations
|
||||
Conversations::ReopenSnoozedConversationsJob.perform_later
|
||||
|
||||
# Job to auto-resolve conversations
|
||||
Account::ConversationsResolutionSchedulerJob.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user