diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-09-02 19:15:42 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-09-02 19:15:42 +0800 |
commit | 39c090fecbdce0031d789a2da5826d25a59c73a4 (patch) | |
tree | 7541d66fba42591488e8c9caa7a1a1040a458de9 /lib | |
parent | d2cfcb3ec1327cd9dd901dcbe8c927e3c43cfb38 (diff) | |
download | gitlab-ce-39c090fecbdce0031d789a2da5826d25a59c73a4.tar.gz |
Calculate real queueing time to exclude gaps from:
retries and probably also manual actions!
Feedback:
* https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14735478
* https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14737804
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/pipeline_duration.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/gitlab/ci/pipeline_duration.rb b/lib/gitlab/ci/pipeline_duration.rb index e37ba19bca9..baf84954b7e 100644 --- a/lib/gitlab/ci/pipeline_duration.rb +++ b/lib/gitlab/ci/pipeline_duration.rb @@ -106,17 +106,27 @@ module Gitlab end end - def self.from_builds(builds) + def self.from_pipeline(pipeline) + status = %w[success failed running canceled] + builds = pipeline.builds.latest.where(status: status) + + duration = from_builds(builds, :started_at, :finished_at).duration + queued = from_builds(builds, :queued_at, :started_at).duration + + [duration, pipeline.started_at - pipeline.created_at + queued] + end + + def self.from_builds(builds, from, to) now = Time.now periods = builds.map do |b| - Period.new(b.started_at || now, b.finished_at || now) + Period.new(b.public_send(from) || now, b.public_send(to) || now) end new(periods) end - attr_reader :duration, :pending_duration + attr_reader :duration def initialize(periods) process(periods.sort_by(&:first)) @@ -125,10 +135,7 @@ module Gitlab private def process(periods) - merged = process_periods(periods) - - @duration = process_duration(merged) - @pending_duration = process_pending_duration(merged) + @duration = process_duration(process_periods(periods)) end def process_periods(periods) @@ -157,13 +164,6 @@ module Gitlab result + per.duration end end - - def process_pending_duration(periods) - return 0 if periods.empty? - - total = periods.last.last - periods.first.first - total - duration - end end end end |