Sha256: 32b8089c9fb1556f7b0f0a5d7af16f137094bd87f37c975140ea105e4f9ad0b0

Contents?: true

Size: 1.36 KB

Versions: 44

Compression:

Stored size: 1.36 KB

Contents

module Fluent

  #Monkey-patch fluentd class (EngineClass) to support shutdown for input plugin.
  #This will be called when USR1 signal is received
  class EngineClass
    #Send shutdown to all the sources
    def shutdown_source
      @sources.map {|s|
        Thread.new do
          begin
            s.shutdown
          rescue => e
            $log.warn "unexpected error while shutting down", :error_class=>e.class, :error=>e
            $log.warn_backtrace
          end
        end
      }.each {|t|
        t.join
      }
    end
  end

  module FlushSupport
    def initialize
      super
      install_custom_signal_handler
    end

    #Hack: All that has been added here is `Fluent::Engine.shutdown_source`. This should be in
    #fluentd's supervisor#install_main_process_signal_handlers
    def install_custom_signal_handler
      trap :USR1 do
        $log.debug "fluentd main process get SIGUSR1"
        $log.info "force flushing buffered events"
        #@log.reopen!

        # Creating new thread due to mutex can't lock
        # in main thread during trap context
        Thread.new {
          begin
            Fluent::Engine.shutdown_source
            Fluent::Engine.flush!
            $log.debug "flushing thread: flushed"
          rescue Exception => e
            $log.warn "flushing thread error: #{e}"
          end
        }.run
      end
    end
  end

end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
flydata-0.8.10.2 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.10.1 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.9.11 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.10 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.9 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.8 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.7 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.6 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.5 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.4 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.3 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.2 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.1 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.8.0 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.19 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.18 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.17 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.16 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.15 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb
flydata-0.7.14 lib/flydata/fluent-plugins/flydata_plugin_ext/flush_support.rb