Class: Embulk::Output::ExampleOutputPlugin

Inherits:
Embulk::OutputPlugin show all
Defined in:
lib/embulk/data/bundle/embulk/output/example.rb

Instance Attribute Summary

Attributes inherited from Embulk::OutputPlugin

#index, #schema, #task

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Embulk::OutputPlugin

cleanup, from_java, #init, new_java

Constructor Details

#initialize(task, schema, index) ⇒ ExampleOutputPlugin

Returns a new instance of ExampleOutputPlugin.



25
26
27
28
29
30
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 25

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

Class Method Details

.resume(task, schema, count, &control) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 16

def self.resume(task, schema, count, &control)
  puts "Example output started."
  task_reports = yield(task)
  puts "Example output finished. Commit reports = #{task_reports.to_json}"

  next_config_diff = {}
  return next_config_diff
end

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



8
9
10
11
12
13
14
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 8

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

  resume(task, schema, count, &control)
end

Instance Method Details

#abortObject



46
47
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 46

def abort
end

#add(page) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 35

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

#closeObject



32
33
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 32

def close
end

#commitObject



49
50
51
52
53
54
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 49

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

#finishObject



43
44
# File 'lib/embulk/data/bundle/embulk/output/example.rb', line 43

def finish
end