Class: Fluent::Plugin::TailInput::TailWatcher::LineBufferTimerFlusher

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_tail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log, flush_interval, &flush_method) ⇒ LineBufferTimerFlusher

Returns a new instance of LineBufferTimerFlusher.



1193
1194
1195
1196
1197
1198
1199
# File 'lib/fluent/plugin/in_tail.rb', line 1193

def initialize(log, flush_interval, &flush_method)
  @log = log
  @flush_interval = flush_interval
  @flush_method = flush_method
  @start = nil
  @line_buffer = nil
end

Instance Attribute Details

#line_bufferObject

Returns the value of attribute line_buffer.



1191
1192
1193
# File 'lib/fluent/plugin/in_tail.rb', line 1191

def line_buffer
  @line_buffer
end

Instance Method Details

#close(tw) ⇒ Object



1213
1214
1215
1216
1217
1218
# File 'lib/fluent/plugin/in_tail.rb', line 1213

def close(tw)
  return unless @line_buffer

  @flush_method.call(tw, @line_buffer)
  @line_buffer = nil
end

#on_notify(tw) ⇒ Object



1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
# File 'lib/fluent/plugin/in_tail.rb', line 1201

def on_notify(tw)
  unless @start && @flush_method
    return
  end

  if Time.now - @start >= @flush_interval
    @flush_method.call(tw, @line_buffer) if @line_buffer
    @line_buffer = nil
    @start = nil
  end
end

#reset_timerObject



1220
1221
1222
1223
1224
# File 'lib/fluent/plugin/in_tail.rb', line 1220

def reset_timer
  return unless @flush_interval

  @start = Time.now
end