Class: Fluent::GCS::CommandObjectCreator

Inherits:
ObjectCreator show all
Defined in:
lib/fluent/plugin/gcs/object_creator.rb

Instance Method Summary collapse

Methods inherited from ObjectCreator

#content_encoding, #content_type, #create, #file_extension

Constructor Details

#initialize(command_parameter: nil, log: nil) ⇒ CommandObjectCreator

Returns a new instance of CommandObjectCreator.



107
108
109
110
111
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 107

def initialize(command_parameter: nil, log: nil)
  @command_parameter = command_parameter
  @log = log
  check_command
end

Instance Method Details

#write(chunk, io) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fluent/plugin/gcs/object_creator.rb', line 113

def write(chunk, io)
  parameter = @command_parameter.nil? || @command_parameter.empty? ? default_parameter : @command_parameter
  cmd = [command, *parameter.shellsplit, "-c"]
  status = Open3.pipeline_w(cmd, out: io.path) do |stdin, wait_thrs|
    chunk.write_to(stdin)
    stdin.close
    wait_thrs.last.value
  end

  handle_failure(chunk, io, status) unless status.success?
end