lib/logstash/plugin_mixins/jdbc/value_tracking.rb in logstash-input-jdbc-4.3.14 vs lib/logstash/plugin_mixins/jdbc/value_tracking.rb in logstash-input-jdbc-4.3.16
- old
+ new
@@ -3,32 +3,30 @@
module LogStash module PluginMixins module Jdbc
class ValueTracking
def self.build_last_value_tracker(plugin)
+ handler = plugin.record_last_run ? FileHandler.new(plugin.last_run_metadata_path) : NullFileHandler.new(plugin.last_run_metadata_path)
+ if plugin.record_last_run
+ handler = FileHandler.new(plugin.last_run_metadata_path)
+ end
+ if plugin.clean_run
+ handler.clean
+ end
+
if plugin.use_column_value && plugin.tracking_column_type == "numeric"
# use this irrespective of the jdbc_default_timezone setting
- klass = NumericValueTracker
+ NumericValueTracker.new(handler)
else
if plugin.jdbc_default_timezone.nil? || plugin.jdbc_default_timezone.empty?
# no TZ stuff for Sequel, use Time
- klass = TimeValueTracker
+ TimeValueTracker.new(handler)
else
# Sequel does timezone handling on DateTime only
- klass = DateTimeValueTracker
+ DateTimeValueTracker.new(handler)
end
end
-
- handler = NullFileHandler.new(plugin.last_run_metadata_path)
- if plugin.record_last_run
- handler = FileHandler.new(plugin.last_run_metadata_path)
- end
- if plugin.clean_run
- handler.clean
- end
-
- instance = klass.new(handler)
end
attr_reader :value
def initialize(handler)
@@ -49,9 +47,10 @@
end
private
def common_set_initial(method_symbol, default)
persisted = @file_handler.read
+
if persisted && persisted.respond_to?(method_symbol)
@value = persisted
else
@file_handler.clean
@value = default