Class: Fluent::Plugin::SQLInput::StateStore

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ StateStore



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/fluent/plugin/in_sql.rb', line 266

def initialize(path)
  require 'yaml'

  @path = path
  if File.exists?(@path)
    @data = YAML.load_file(@path)
    if @data == false || @data == []
      # this happens if an users created an empty file accidentally
      @data = {}
    elsif !@data.is_a?(Hash)
      raise "state_file on #{@path.inspect} is invalid"
    end
  else
    @data = {}
  end
end

Instance Method Details

#last_recordsObject



283
284
285
# File 'lib/fluent/plugin/in_sql.rb', line 283

def last_records
  @data['last_records'] ||= {}
end

#update!Object



287
288
289
290
291
# File 'lib/fluent/plugin/in_sql.rb', line 287

def update!
  File.open(@path, 'w') {|f|
    f.write YAML.dump(@data)
  }
end