module Daengine class TaxonomyProcessor @@last_read_time = 2.days.ago def self.is_windows? processor, platform, *rest = RUBY_PLATFORM.split("-") platform =~ /mswin/ || platform =~ /mingw/ end def self.process_taxonomy_file file = Daengine.config[:taxonomy_xml_filepath] raise "ERROR: TaxonomyProcessor: Invalid taxonomy_xml_filepath provided. Unable to read from #{file}" unless File::exist?(file) time = self.read_last_process_time if not time.blank? @@last_read_time = time end Daengine.log("TaxonomyProcessor: Last process time was #{@@last_read_time}", "info") if (File.mtime(file) > @@last_read_time) Daengine.log("TaxonomyProcessor: Processing file #{file} --- #{File.mtime(file)}", "info") open_file = File.open(file, 'rb') Daengine::TaxonomyParser.parse_taxonomy_file(open_file) Daengine.log("TaxonomyProcessor: Finished processing #{file}", "info") @@last_read_time = File.mtime(file) + 1.second self.save_last_read_time Daengine.log("TaxonomyProcessor: Last process time set to #{@@last_read_time}", "info") else Daengine.log("TaxonomyProcessor: No updates to taxonomy since last process task.", "info") end end def self.save_last_read_time begin target = Daengine.config[:taxonomyengine_yml_file] content = "last_read_time: #{@@last_read_time}" File.open(target, "w+") do |f| f.write(content) end rescue Exception => e puts e Daengine.log("ERROR: TaxonomyProcessor: Failed to write to #{target}.", "error") end end def self.read_last_process_time time = "" begin target = Daengine.config[:taxonomyengine_yml_file] property = YAML.load_file(target) time = property['last_read_time'] rescue Exception => e puts e Daengine.log("ERROR: TaxonomyProcessor: Failed to read from #{target}", "error") end time end end end