diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-09-02 23:43:10 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-09-02 23:43:10 +0800 |
commit | 7aaed299eb744e524a1597ceed923c14b556ef20 (patch) | |
tree | 91c893bac6e30b905a86f1c1713942af4848690f | |
parent | 8d96062f2386a4e9c30631c35cb41f827cc25beb (diff) | |
download | gitlab-ce-7aaed299eb744e524a1597ceed923c14b556ef20.tar.gz |
Just sum all the queuing time, indication for needing more runners
-rw-r--r-- | lib/gitlab/ci/pipeline_duration.rb | 13 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/gitlab/ci/pipeline_duration.rb b/lib/gitlab/ci/pipeline_duration.rb index 0c7c38e2b67..ac68fd0272f 100644 --- a/lib/gitlab/ci/pipeline_duration.rb +++ b/lib/gitlab/ci/pipeline_duration.rb @@ -107,19 +107,20 @@ module Gitlab end def self.from_pipeline(pipeline) + now = Time.now status = %w[success failed running canceled] builds = pipeline.builds.latest.where(status: status) - running = from_builds(builds, :started_at, :finished_at).duration - total = from_builds(builds, :queued_at, :finished_at).duration + running = from_builds(builds, :started_at, :finished_at, now).duration pending = pipeline.started_at - pipeline.created_at + queuing = builds.inject(0) do |result, job| + result + ((job.started_at || now) - (job.queued_at || now)) + end - [running, pending + total - running] + [running, pending + queuing] end - def self.from_builds(builds, from, to) - now = Time.now - + def self.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 diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 2c04ef298bc..194c3fc01f1 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -156,7 +156,7 @@ describe Ci::Pipeline, models: true do pipeline.reload expect(pipeline.duration).to eq(40) - expect(pipeline.pending_duration).to eq(25) + expect(pipeline.pending_duration).to eq(45) end end |