app/models/logical/naf/log_reader.rb in naf-2.1.9 vs app/models/logical/naf/log_reader.rb in naf-2.1.10
- old
+ new
@@ -5,12 +5,12 @@
class LogReader
DATE_REGEX = /((\d){4}-(\d){2}-(\d){2} (\d){2}:(\d){2}:(\d){2} UTC)/
def log_files
- tree = bucket.objects.with_prefix(prefix).as_tree
- directories = tree.children.select(&:branch?).collect(&:prefix).uniq
+ tree = bucket.objects.with_prefix(job_log_prefix).as_tree
+ directories = tree.children.select(&:branch?).collect(&:job_log_prefix).uniq
files = []
directories.each do |directory|
tree = bucket.objects.with_prefix(directory).as_tree
tree.children.select(&:leaf?).collect(&:key).each do |file|
@@ -19,12 +19,12 @@
end
return sort_files(files)
end
def runner_log_files
- tree = bucket.objects.with_prefix(prefix(true)).as_tree
- directories = tree.children.select(&:branch?).collect(&:prefix).uniq
+ tree = bucket.objects.with_prefix(runner_log_prefix).as_tree
+ directories = tree.children.select(&:branch?).collect(&:runner_log_prefix).uniq
files = []
directories.each do |directory|
tree = bucket.objects.with_prefix(directory).as_tree
tree.children.select(&:leaf?).collect(&:key).each do |file|
@@ -38,11 +38,12 @@
def retrieve_file(file)
bucket.objects[file].read
end
def retrieve_job_files(job_id)
- tree = bucket.objects.with_prefix(prefix + "#{job_id}").as_tree
+ return [] unless job_id.present?
+ tree = bucket.objects.with_prefix(job_log_prefix + "#{job_id}").as_tree
sort_files(tree.children.select(&:leaf?).collect(&:key))
end
private
@@ -55,15 +56,15 @@
def bucket
@bucket ||= s3.buckets[NAF_BUCKET]
end
- def prefix(runner_logs = false)
- if runner_logs
- "#{NAF_LOG_PATH}/#{creation_time}/#{::Naf::NAF_DATABASE_HOSTNAME}/#{::Naf::NAF_DATABASE}/#{::Naf.schema_name}/runners/"
- else
- "#{NAF_LOG_PATH}/#{creation_time}/#{::Naf::NAF_DATABASE_HOSTNAME}/#{::Naf::NAF_DATABASE}/#{::Naf.schema_name}/jobs/"
- end
+ def runner_log_prefix
+ @runner_log_prefix ||= "#{NAF_LOG_PATH}/#{creation_time}/#{::Naf::NAF_DATABASE_HOSTNAME}/#{::Naf::NAF_DATABASE}/#{::Naf.schema_name}/runners/"
+ end
+
+ def job_log_prefix
+ @job_log_prefix ||= "#{NAF_LOG_PATH}/#{creation_time}/#{::Naf::NAF_DATABASE_HOSTNAME}/#{::Naf::NAF_DATABASE}/#{::Naf.schema_name}/jobs/"
end
def sort_files(files)
files.sort do |x, y|
-Time.parse(x.scan(/\d{8}_\d{4}/).last).to_i <=> -Time.parse(y.scan(/\d{8}_\d{4}/).last).to_i