Class: CommandTower::Messaging::Execution::Scheduler
- Inherits:
-
Object
- Object
- CommandTower::Messaging::Execution::Scheduler
- Defined in:
- app/services/command_tower/messaging/execution/scheduler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #enqueue(channel_delivery_id) ⇒ Object
- #enqueue_all(ids = @channel_delivery_ids) ⇒ Object
-
#initialize(channel_delivery_ids) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #schedule_after_commit ⇒ Object
Constructor Details
#initialize(channel_delivery_ids) ⇒ Scheduler
Returns a new instance of Scheduler.
11 12 13 |
# File 'app/services/command_tower/messaging/execution/scheduler.rb', line 11 def initialize(channel_delivery_ids) @channel_delivery_ids = Array(channel_delivery_ids).compact.uniq end |
Class Method Details
.schedule_after_commit(channel_delivery_ids) ⇒ Object
7 8 9 |
# File 'app/services/command_tower/messaging/execution/scheduler.rb', line 7 def self.schedule_after_commit(channel_delivery_ids) new(channel_delivery_ids).schedule_after_commit end |
Instance Method Details
#enqueue(channel_delivery_id) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/services/command_tower/messaging/execution/scheduler.rb', line 26 def enqueue(channel_delivery_id) Messaging::ChannelDeliveryExecutionJob.perform_later(channel_delivery_id) delivery = Messaging::ChannelDelivery.find_by(id: channel_delivery_id) OperationLogger.scheduled(channel_delivery: delivery) if delivery rescue StandardError => error OperationLogger.enqueue_failed(channel_delivery_id:, error:) # Leave status as queued — Execution::Recovery will redrive. nil end |
#enqueue_all(ids = @channel_delivery_ids) ⇒ Object
22 23 24 |
# File 'app/services/command_tower/messaging/execution/scheduler.rb', line 22 def enqueue_all(ids = @channel_delivery_ids) ids.each { |id| enqueue(id) } end |
#schedule_after_commit ⇒ Object
15 16 17 18 19 20 |
# File 'app/services/command_tower/messaging/execution/scheduler.rb', line 15 def schedule_after_commit return if @channel_delivery_ids.empty? ids = @channel_delivery_ids ActiveRecord.after_all_transactions_commit { enqueue_all(ids) } end |