Class: Inboxable::PollingReceiverWorker
- Inherits:
-
Object
- Object
- Inboxable::PollingReceiverWorker
- Includes:
- Sidekiq::Job
- Defined in:
- lib/inboxable/polling_receiver_worker.rb
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
7 8 9 |
# File 'lib/inboxable/polling_receiver_worker.rb', line 7 def perform Inboxable.configuration.orm == :activerecord ? perform_activerecord : perform_mongoid end |
#perform_activerecord ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/inboxable/polling_receiver_worker.rb', line 11 def perform_activerecord Inboxable.inbox_model.pending .where(last_attempted_at: [..Time.zone.now, nil]) .find_in_batches(batch_size: ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i) .each do |batch| batch.each do |inbox| inbox.processor_class_name.constantize.perform_async(inbox.id) inbox.update(last_attempted_at: 1.minute.from_now, status: :processed, allow_processing: false) end end end |
#perform_mongoid ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/inboxable/polling_receiver_worker.rb', line 23 def perform_mongoid batch_size = ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i Inboxable.inbox_model.pending .any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: nil }) .each_slice(batch_size) do |batch| batch.each do |inbox| inbox.processor_class_name.constantize.perform_async(inbox.id.to_s) inbox.update(last_attempted_at: 1.minute.from_now, status: :processed, allow_processing: false) end end end |