Class: CommandTower::Messaging::Accept::HandoffScheduler

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/accept/handoff_scheduler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(communication_id) ⇒ HandoffScheduler

Returns a new instance of HandoffScheduler.



15
16
17
# File 'app/services/command_tower/messaging/accept/handoff_scheduler.rb', line 15

def initialize(communication_id)
  @communication_id = communication_id
end

Class Method Details

.enqueue(communication_id) ⇒ Object



11
12
13
# File 'app/services/command_tower/messaging/accept/handoff_scheduler.rb', line 11

def self.enqueue(communication_id)
  new(communication_id).enqueue
end

.schedule_after_commit(communication_id) ⇒ Object



7
8
9
# File 'app/services/command_tower/messaging/accept/handoff_scheduler.rb', line 7

def self.schedule_after_commit(communication_id)
  new(communication_id).schedule_after_commit
end

Instance Method Details

#enqueueObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/command_tower/messaging/accept/handoff_scheduler.rb', line 23

def enqueue
  Messaging::HandoffJob.perform_later(@communication_id)
  communication = Messaging::Communication.find_by(id: @communication_id)
  if communication
    Handoff::OperationLogger.scheduled(communication:)
  end
rescue StandardError => error
  Handoff::OperationLogger.enqueue_failed(
    communication_id: @communication_id,
    error:,
  )
  # Leave execution_handoff_status as pending — recovery will redrive.
  nil
end

#schedule_after_commitObject



19
20
21
# File 'app/services/command_tower/messaging/accept/handoff_scheduler.rb', line 19

def schedule_after_commit
  ActiveRecord.after_all_transactions_commit { enqueue }
end