Class: Fluent::TumblrOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTumblrOutput

Returns a new instance of TumblrOutput.



11
12
13
# File 'lib/fluent/plugin/out_tumblr.rb', line 11

def initialize
  super
end

Instance Attribute Details

#tumblr_clientObject

Returns the value of attribute tumblr_client.



31
32
33
# File 'lib/fluent/plugin/out_tumblr.rb', line 31

def tumblr_client
  @tumblr_client
end

Instance Method Details

#configure(conf) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/out_tumblr.rb', line 33

def configure(conf)
  super

  @tags = ERB.new(@tags_template)
  @caption = ERB.new(@caption_template)
  raise "Unsupport post_type: #{@post_type}" unless @post_type == 'picture'

  Tumblr.configure do |config|
    config.consumer_key = @consumer_key
    config.consumer_secret = @consumer_secret
    config.oauth_token = @oauth_token
    config.oauth_token_secret = @oauth_token_secret
  end
  @tumblr_client = Tumblr::Client.new

  @q = Queue.new
end

#emit(tag, es, chain) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/out_tumblr.rb', line 65

def emit(tag, es, chain)
  es.each {|time, record|
    param = OpenStruct.new
    param.tag = tag
    param.time = time
    param.record = record

    @q.push param
  }

  chain.next
end

#shutdownObject



59
60
61
62
63
# File 'lib/fluent/plugin/out_tumblr.rb', line 59

def shutdown
  super

  Thread.kill(@thread)
end

#startObject



51
52
53
54
55
56
57
# File 'lib/fluent/plugin/out_tumblr.rb', line 51

def start
  super

  @thread = Thread.new(&method(:post))
rescue
  $log.warn "raises exception: #{$!.class}, '#{$!.message}"
end