Class: Rawscsi::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/rawscsi/index.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #is_active_record, #model

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Rawscsi::Base

Instance Method Details

#delete(id_array) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rawscsi/index.rb', line 24

def delete(id_array)
  if id_array.length < 20000
    delete_from_amazon(id_array)
  else
    id_array.each_slice(20000).to_a.each do |sub_array|
     delete_from_amazon(sub_array)
    end
  end
end

#upload(obj_array) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rawscsi/index.rb', line 5

def upload(obj_array)
  batch_size = 0
  current_batch = []

  obj_array.each do |obj|
    sdf = format_to_sdf(obj)
    size = sdf.to_json.bytesize
    if (batch_size + size) < max_size
      current_batch << sdf
      batch_size = batch_size + size
    else
      post_to_amazon(current_batch)
      current_batch = []
      batch_size = 0
    end
  end
  post_to_amazon(current_batch)
end