Class: Daengine::TaxonomyProcessor
- Inherits:
-
Object
- Object
- Daengine::TaxonomyProcessor
- Defined in:
- lib/daengine/taxonomy_processor.rb
Constant Summary collapse
- @@last_read_time =
2.days.ago
Class Method Summary collapse
- .is_windows? ⇒ Boolean
- .process_taxonomy_file ⇒ Object
- .read_last_process_time ⇒ Object
- .save_last_read_time ⇒ Object
Class Method Details
.is_windows? ⇒ Boolean
6 7 8 9 |
# File 'lib/daengine/taxonomy_processor.rb', line 6 def self.is_windows? processor, platform, *rest = RUBY_PLATFORM.split("-") platform =~ /mswin/ || platform =~ /mingw/ end |
.process_taxonomy_file ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/daengine/taxonomy_processor.rb', line 11 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 |
.read_last_process_time ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/daengine/taxonomy_processor.rb', line 45 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 |
.save_last_read_time ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/daengine/taxonomy_processor.rb', line 32 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 |