Class: Embulk::OutputExample

Inherits:
OutputPlugin show all
Defined in:
lib/embulk/data/bundle/embulk/output_example.rb

Instance Attribute Summary

Attributes inherited from OutputPlugin

#index, #schema, #task

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OutputPlugin

java_object

Constructor Details

#initialize(task, schema, index) ⇒ OutputExample

Returns a new instance of OutputExample.



19
20
21
22
23
24
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 19

def initialize(task, schema, index)
  puts "Example output thread #{index}..."
  super
  @message = task.param('message', :string)
  @records = 0
end

Class Method Details

.transaction(config, schema, processor_count, &control) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 7

def self.transaction(config, schema, processor_count, &control)
  task = {
    'message' => config.param('message', :string, default: "record")
  }

  puts "Example output started."
  commit_reports = yield(task)
  puts "Example output finished. Commit reports = #{commit_reports.to_json}"

  return {}
end

Instance Method Details

#abortObject



40
41
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 40

def abort
end

#add(page) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 29

def add(page)
  page.each do |record|
    hash = Hash[schema.names.zip(record)]
    puts "#{@message}: #{hash.to_json}"
    @records += 1
  end
end

#closeObject



26
27
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 26

def close
end

#commitObject



43
44
45
46
47
48
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 43

def commit
  commit_report = {
    "records" => @records
  }
  return commit_report
end

#finishObject



37
38
# File 'lib/embulk/data/bundle/embulk/output_example.rb', line 37

def finish
end