Class: Sidekiq::Job::Iterable::ActiveRecordEnumerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/job/iterable/active_record_enumerator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(relation, cursor: nil, **options) ⇒ ActiveRecordEnumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ActiveRecordEnumerator.

API:

  • private



8
9
10
11
12
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 8

def initialize(relation, cursor: nil, **options)
  @relation = relation
  @cursor = cursor
  @options = options
end

Instance Method Details

#batchesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



22
23
24
25
26
27
28
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 22

def batches
  Enumerator.new(-> { @relation.count }) do |yielder|
    @relation.find_in_batches(**@options, start: @cursor) do |batch|
      yielder.yield(batch, batch.first.id)
    end
  end
end

#recordsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



14
15
16
17
18
19
20
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 14

def records
  Enumerator.new(-> { @relation.count }) do |yielder|
    @relation.find_each(**@options, start: @cursor) do |record|
      yielder.yield(record, record.id)
    end
  end
end

#relationsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 30

def relations
  Enumerator.new(-> { relations_size }) do |yielder|
    # Convenience to use :batch_size for all the
    # ActiveRecord batching methods.
    options = @options.dup
    options[:of] ||= options.delete(:batch_size)

    @relation.in_batches(**options, start: @cursor) do |relation|
      first_record = relation.first
      yielder.yield(relation, first_record.id)
    end
  end
end