Sha256: 8f2cf789f4b28950762a33eada90083d07ecc54e55ed42b3c2ff5bb2a5ed52c8

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'sidekiq'

module Inboxable
  class PollingReceiverWorker
    include Sidekiq::Job

    def perform
      Inboxable.configuration.orm == :activerecord ? perform_activerecord : perform_mongoid
    end

    def perform_activerecord
      Inbox.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

    def perform_mongoid
      batch_size = ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i
      Inbox.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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inboxable-0.1.0 lib/inboxable/polling_receiver_worker.rb