Module: AWS::Core::Collection::Batchable

Includes:
AWS::Core::Collection
Defined in:
lib/aws/core/collection/batchable.rb

Instance Method Summary collapse

Methods included from AWS::Core::Collection

#each, #enum, #first, #in_groups_of, #page

Instance Method Details

#each_batch(options = {}, &block) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/aws/core/collection/batchable.rb', line 22

def each_batch options = {}, &block

  raise NotImplementedError

  each_opts  = options.dup

  limit = each_opts.delete(:limit)

  next_token, skip = each_opts.delete(:next_token)

  total = 0  # count of items yeileded across all batches

  begin

    batch = []

    next_token = _each_item(next_token, each_opts.dup) do |item|
      total += 1
      batch << item

      if limit and total == limit
        yield(batch)
      end

    end

  end until next_token.nil? or (limit and limit = total)









  options = options.dup

  limit = options.delete(:limit)
  batch_size = options.delete(:batch_size)
  options.delete(:next_token) if [nil, ''].include?(options[:next_token])

  total = 0  # count of items yeileded across all batches

  _each_response(options, limit, batch_size) do |response|

    batch = []
    each_item(response) do |item|
      batch << item
      if limit and (total += 1) == limit
        yield(batch)
        return
      end
    end

    yield(batch)

    batch.size

  end

end