summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline_duration.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-09-06 19:14:28 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-09-06 19:14:28 +0800
commit3a68c98973c2c17e0c6e57184c4b2605a2dd274e (patch)
tree5dd071cc421d4f63975974bd54e8a8e8effeec1a /lib/gitlab/ci/pipeline_duration.rb
parentb92c75ab982e123e2e1efc189e35b84c0ffd1c27 (diff)
downloadgitlab-ce-3a68c98973c2c17e0c6e57184c4b2605a2dd274e.tar.gz
Just use module because there's nothing to save, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14992064
Diffstat (limited to 'lib/gitlab/ci/pipeline_duration.rb')
-rw-r--r--lib/gitlab/ci/pipeline_duration.rb24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/gitlab/ci/pipeline_duration.rb b/lib/gitlab/ci/pipeline_duration.rb
index 9fe4996fc09..0333807263f 100644
--- a/lib/gitlab/ci/pipeline_duration.rb
+++ b/lib/gitlab/ci/pipeline_duration.rb
@@ -2,7 +2,7 @@ module Gitlab
module Ci
# # Introduction - total running time
#
- # The problem this class is trying to solve is finding the total running
+ # The problem this module is trying to solve is finding the total running
# time amongst all the jobs, excluding retries and pending (queue) time.
# We could reduce this problem down to finding the union of periods.
#
@@ -76,7 +76,9 @@ module Gitlab
# (4 - 1) + (7 - 6) => 4
#
# That is 4 is the answer in the example.
- class PipelineDuration
+ module PipelineDuration
+ extend self
+
PeriodStruct = Struct.new(:first, :last)
class Period < PeriodStruct
def duration
@@ -84,33 +86,27 @@ module Gitlab
end
end
- def self.from_pipeline(pipeline)
+ def from_pipeline(pipeline)
status = %w[success failed running canceled]
builds = pipeline.builds.latest.where(status: status)
- from_builds(builds, :started_at, :finished_at).duration
+ from_builds(builds, :started_at, :finished_at)
end
- def self.from_builds(builds, from, to, now = Time.now)
+ def from_builds(builds, from, to, now = Time.now)
periods = builds.map do |b|
Period.new(b.public_send(from) || now, b.public_send(to) || now)
end
- new(periods)
+ from_periods(periods)
end
- attr_reader :duration
-
- def initialize(periods)
- process(periods.sort_by(&:first))
+ def from_periods(periods)
+ process_duration(process_periods(periods.sort_by(&:first)))
end
private
- def process(periods)
- @duration = process_duration(process_periods(periods))
- end
-
def process_periods(periods)
return periods if periods.empty?