Skip to content

Commit

Permalink
Merge pull request #315 from iberianpig/feature/input_read_from_io
Browse files Browse the repository at this point in the history
fix: cutting out read_from_io from Input class
  • Loading branch information
iberianpig authored Jan 15, 2024
2 parents 3a6e285 + 007b94f commit e93672d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/fusuma/plugin/inputs/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ def self.select(inputs)

input = inputs.find { |i| i.io == io }

begin
# NOTE: io.readline is blocking method
# each input plugin must write line to pipe (include `\n`)
line = io.readline(chomp: true)
rescue EOFError => e
MultiLogger.error "#{input.class.name}: #{e}"
MultiLogger.error "Shutdown fusuma process..."
Process.kill("TERM", Process.pid)
rescue => e
MultiLogger.error "#{input.class.name}: #{e}"
exit 1
end
input.create_event(record: line)
input.create_event(record: input.read_from_io)
end

# @return [String, Record]
# IO#readline is blocking method
# so input plugin must write line to pipe (include `\n`)
# or, override read_from_io and implement your own read method
def read_from_io
io.readline(chomp: true)
rescue EOFError => e
MultiLogger.error "#{self.class.name}: #{e}"
MultiLogger.error "Shutdown fusuma process..."
Process.kill("TERM", Process.pid)
rescue => e
MultiLogger.error "#{self.class.name}: #{e}"
exit 1
end

# @return [Integer]
Expand Down
5 changes: 5 additions & 0 deletions spec/fusuma/plugin/inputs/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def io
it { is_expected.to be_a IO }
end

describe "#read_from_io" do
subject { dummy_input.read_from_io }
it { is_expected.to eq "hoge" }
end

describe "#config_params" do
subject { dummy_input.config_params(:dummy) }
it { is_expected.to eq("dummy") }
Expand Down

0 comments on commit e93672d

Please sign in to comment.