Class: Fluent::HRForecastOutput::PostThread

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin) ⇒ PostThread

Returns a new instance of PostThread.



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_hrforecast.rb', line 99

def initialize(plugin)
  require 'thread'
  @queue = Queue.new
  @plugin = plugin
  @thread = Thread.new do
    begin
      post(@queue.deq) while true
    ensure
      post(@queue.deq) while not @queue.empty?
    end
  end
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



97
98
99
# File 'lib/fluent/plugin/out_hrforecast.rb', line 97

def queue
  @queue
end

Instance Method Details

#post(events) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/fluent/plugin/out_hrforecast.rb', line 112

def post(events)
  begin
    @plugin.post_events(events) if events.size > 0
  rescue => e
    @plugin.log.warn "HTTP POST in background Error occures to HRforecast server", :error_class => e.class, :error => e.message
  end
end

#shutdownObject



120
121
122
123
# File 'lib/fluent/plugin/out_hrforecast.rb', line 120

def shutdown
  @thread.terminate
  @thread.join
end