Class: Fluent::SlackRTMInput

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

Instance Method Summary collapse

Instance Method Details

#emit(data) ⇒ Object



28
29
30
31
# File 'lib/fluent/plugin/in_slackrtm.rb', line 28

def emit(data)
  time = Time.now.to_i
  Fluent::Engine.emit(tag, time, data)
end

#shutdownObject



24
25
26
# File 'lib/fluent/plugin/in_slackrtm.rb', line 24

def shutdown
  Thread.kill(@messages_thread)
end

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fluent/plugin/in_slackrtm.rb', line 11

def start
  super
  @messages_thread = Thread.new do
    url = SlackRTM.get_url token: token
    client = SlackRTM::Client.new websocket_url: url
    client.on(:message) do |data|
      emit(data)
    end
    client.main_loop
  end
  @messages_thread.abort_on_exception = true
end