- def pipeline_log_history(job_uuids)
- results = []
-
- log_history = Log.where(event_type: 'stderr',
- object_uuid: job_uuids).order('id DESC')
- if !log_history.results.empty?
- reversed_results = log_history.results.reverse
- reversed_results.each do |entry|
- if entry.andand.properties
- properties = entry.properties
- text = properties[:text]
- if text
- results = results.concat text.split("\n")
- end
+ # Merge (started_at, finished_at) time range into the list of time ranges in
+ # timestamps (timestamps must be sorted and non-overlapping).
+ # return the updated timestamps list.
+ def merge_range timestamps, started_at, finished_at
+ # in the comments below, 'i' is the entry in the timestamps array and 'j'
+ # is the started_at, finished_at range which is passed in.
+ timestamps.each_index do |i|
+ if started_at
+ if started_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+ # 'j' started and ended during 'i'
+ return timestamps
+ end
+
+ if started_at < timestamps[i][0] and finished_at >= timestamps[i][0] and finished_at <= timestamps[i][1]
+ # 'j' started before 'i' and finished during 'i'
+ # re-merge range between when 'j' started and 'i' finished
+ finished_at = timestamps[i][1]
+ timestamps.delete_at i
+ return merge_range timestamps, started_at, finished_at
+ end
+
+ if started_at >= timestamps[i][0] and started_at <= timestamps[i][1]
+ # 'j' started during 'i' and finished sometime after
+ # move end time of 'i' back
+ # re-merge range between when 'i' started and 'j' finished
+ started_at = timestamps[i][0]
+ timestamps.delete_at i
+ return merge_range timestamps, started_at, finished_at
+ end
+
+ if finished_at < timestamps[i][0]
+ # 'j' finished before 'i' started, so insert before 'i'
+ timestamps.insert i, [started_at, finished_at]
+ return timestamps