Class: StatePersistor
- Inherits:
-
Object
- Object
- StatePersistor
- Defined in:
- lib/logstash/inputs/sfdc_elf/state_persistor.rb
Overview
Handel what the next procedure should be based on the .sfdc_info_logstash file. States proceed via reading and writing LogDates to the .sfdc_info_logstash file.
Constant Summary collapse
- LOG_KEY =
'SFDC - StatePersistor'
- FILE_PREFIX =
'sfdc_info_logstash'
- DEFAULT_TIME =
'0001-01-01T00:00:00Z'
Instance Method Summary collapse
- #get_last_indexed_log_date ⇒ Object
-
#initialize(base_path, org_id) ⇒ StatePersistor
constructor
A new instance of StatePersistor.
- #update_last_indexed_log_date(date) ⇒ Object
Constructor Details
#initialize(base_path, org_id) ⇒ StatePersistor
Returns a new instance of StatePersistor.
10 11 12 13 |
# File 'lib/logstash/inputs/sfdc_elf/state_persistor.rb', line 10 def initialize(base_path, org_id) @logger = Cabin::Channel.get(LogStash) @path_with_file_name = "#{base_path}/.#{FILE_PREFIX}_#{org_id}" end |
Instance Method Details
#get_last_indexed_log_date ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/logstash/inputs/sfdc_elf/state_persistor.rb', line 20 def get_last_indexed_log_date # Read from .sfdc_info_logstash if it exists, otherwise load @last_read_log_date with DEFAULT_TIME. if File.exist?(@path_with_file_name) # Load last read LogDate from .sfdc_info_logstash. @logger.info("#{LOG_KEY}: .#{@path_with_file_name} does exist, read and return the time on it.") File.read(@path_with_file_name) else # Load default time to ensure getting all possible EventLogFiles from oldest to current. Also # create .sfdc_info_logstash file @logger.info("#{LOG_KEY}: .sfdc_info_logstash does not exist and loaded DEFAULT_TIME to @last_read_instant") update_last_indexed_log_date(DEFAULT_TIME) DEFAULT_TIME end end |
#update_last_indexed_log_date(date) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/logstash/inputs/sfdc_elf/state_persistor.rb', line 42 def update_last_indexed_log_date(date) @logger.info("#{LOG_KEY}: overwriting #{@path_with_file_name} with #{date}") f = File.open(@path_with_file_name, 'w') f.write(date) f.flush f.close end |