Class: Fluent::RSSInput

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



12
13
14
15
16
17
# File 'lib/fluent/plugin/in_rss.rb', line 12

def configure(conf)
  super

  @attrs = @attrs.split(',').map {|attr| attr.strip }
  @current_time = Time.now
end

#emit_rssObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/in_rss.rb', line 34

def emit_rss
  begin
    next_current_time = @current_time
    rss = RSS::Parser.parse(@url)
    rss.items.each do |item|
      record = {}
      @attrs.each do |attr|
        record[attr] = item.send(attr) if item.send(attr)
      end
      time = Time.parse item.date.to_s
      if time > @current_time
        Fluent::Engine.emit @tag, Time.parse(item.date.to_s), record
        next_current_time = time if time > next_current_time
      end
    end
    @current_time = next_current_time
  rescue => e
    log.error e
  end
end

#runObject



27
28
29
30
31
32
# File 'lib/fluent/plugin/in_rss.rb', line 27

def run
  loop do
    Thread.new(&method(:emit_rss))
    sleep @interval
  end
end

#shutdownObject



23
24
25
# File 'lib/fluent/plugin/in_rss.rb', line 23

def shutdown
  Thread.kill(@thread)
end

#startObject



19
20
21
# File 'lib/fluent/plugin/in_rss.rb', line 19

def start
  @thread = Thread.new(&method(:run))
end