app/models/process/naf/log_archiver.rb in naf-2.0.3 vs app/models/process/naf/log_archiver.rb in naf-2.0.4

- old
+ new

@@ -43,24 +43,31 @@ files = Dir[NAF_JOBS_LOG_PATH + "*/*"] files += Dir[NAF_RUNNERS_LOG_PATH + "*/*"] # Sort log files based on time files = files.sort { |x, y| Time.parse(y.scan(DATE_REGEX).first) <=> Time.parse(x.scan(DATE_REGEX).first) } - return files + today = Time.zone.now.to_date + old_files = [] + files.each_with_index do |file, index| + if (today - Time.parse(file.scan(DATE_REGEX).first).to_date).to_i > LOG_RETENTION + old_files = files[index..-1] + break + end + end + + return old_files end def creation_time ::Naf::ApplicationType.first.created_at.strftime("%Y%m%d_%H%M%S") end def archive_old_files(files) copy_files today = Time.zone.now.to_date files.each do |file| - if (today - Time.parse(file.scan(DATE_REGEX).first).to_date).to_i > LOG_RETENTION - logger.info "Archived file: #{file}" - `rm #{file}` - end + logger.info "Archived file: #{file}" + `rm #{file}` end end def copy_files if File.directory?(Naf::LOGGING_ROOT_DIRECTORY + "/naf")