Method: Flydata::Command::Sender#flush_client_buffer

Defined in:
lib/flydata/command/sender.rb

#flush_client_buffer(options = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/flydata/command/sender.rb', line 98

def flush_client_buffer(options = {})
  force_flush = options.has_key?(:force) ? options[:force] : true
  unless process_exist?
    return true if !force_flush || client_buffer_empty?
    log_info_stdout("Process doesn't exist. But, the client buffer is not empty!!") unless options[:quiet]
    raw_start(options)
  end

  log_info_stdout('Stopping input plugins and flushing the client buffer.') unless options[:quiet]
  Kernel.system("kill -USR1 `cat #{pid_file}`")

  retry_count = 12
  1.upto(retry_count) do |i|
    return true if client_buffer_empty?
    log_info_stdout("Waiting for the buffer to get empty... (#{i}/#{retry_count})") unless options[:quiet]
    Kernel.sleep 5
  end

  raise 'Unable to flush client buffer'
end