Class: Fluent::MongoTailInput

Inherits:
Input
  • Object
show all
Includes:
MongoUtil
Defined in:
lib/fluent/plugin/in_mongo_tail.rb

Instance Method Summary collapse

Methods included from MongoUtil

#authenticate, included

Constructor Details

#initializeMongoTailInput

Returns a new instance of MongoTailInput.



24
25
26
27
28
# File 'lib/fluent/plugin/in_mongo_tail.rb', line 24

def initialize
  super
  require 'mongo'
  require 'bson'
end

Instance Method Details

#configure(conf) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/in_mongo_tail.rb', line 30

def configure(conf)
  super

  if !@tag and !@tag_key
    raise ConfigError, "'tag' or 'tag_key' option is required on mongo_tail input"
  end

  @last_id = @id_store_file ? get_last_id : nil

  $log.debug "Setup mongo_tail configuration: mode = #{@id_store_file ? 'persistent' : 'non-persistent'}"
end

#runObject



60
61
62
63
64
# File 'lib/fluent/plugin/in_mongo_tail.rb', line 60

def run
  loop {
    tailoop(Mongo::Cursor.new(@client, cursor_conf))
  }
end

#shutdownObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/fluent/plugin/in_mongo_tail.rb', line 49

def shutdown
  if @id_store_file
    save_last_id
    @file.close
  end

  @thread.join
  @client.db.connection.close
  super
end

#startObject



42
43
44
45
46
47
# File 'lib/fluent/plugin/in_mongo_tail.rb', line 42

def start
  super
  @file = get_id_store_file if @id_store_file
  @client = get_capped_collection
  @thread = Thread.new(&method(:run))
end