Module: Origami::Importer

Defined in:
lib/origami-importer.rb,
lib/origami-importer/batch.rb,
lib/origami-importer/writer.rb

Defined Under Namespace

Classes: Batch, BatchFailed, Writer

Class Method Summary collapse

Class Method Details

.batch(options = {}, &block) ⇒ Object



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
# File 'lib/origami-importer.rb', line 26

def batch(options = {}, &block)
  host = options[:host]
  realm = options[:realm]
  source = options[:source]
  session = options[:session]

  batch = Batch.new(:host => host, :realm => realm, :source => source, :session => session)

  reader = options[:reader]
  writer = Writer.new(batch)

  begin
    batch.open
    reader.relay = batch.relay
    yield reader, writer
  rescue Pebblebed::HttpError => e
    puts "Cannot continue. #{e.message}"
  rescue BatchFailed => e
    puts "Failed. Deleting"
    batch.delete
  else
    puts "Succeeded. Closing."
    batch.close(reader.relay)
  end
end

.import(options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/origami-importer.rb', line 18

def import(options = {})

  Origami::Importer.batch(options) do |reader, writer|
    reader.in_batches { |records| writer << records }
  end

end