Commit 7aaed299 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Just sum all the queuing time, indication for needing more runners

parent 8d96062f
...@@ -107,19 +107,20 @@ module Gitlab ...@@ -107,19 +107,20 @@ module Gitlab
end end
def self.from_pipeline(pipeline) def self.from_pipeline(pipeline)
now = Time.now
status = %w[success failed running canceled] status = %w[success failed running canceled]
builds = pipeline.builds.latest.where(status: status) builds = pipeline.builds.latest.where(status: status)
running = from_builds(builds, :started_at, :finished_at).duration running = from_builds(builds, :started_at, :finished_at, now).duration
total = from_builds(builds, :queued_at, :finished_at).duration
pending = pipeline.started_at - pipeline.created_at pending = pipeline.started_at - pipeline.created_at
queuing = builds.inject(0) do |result, job|
[running, pending + total - running] result + ((job.started_at || now) - (job.queued_at || now))
end end
def self.from_builds(builds, from, to) [running, pending + queuing]
now = Time.now end
def self.from_builds(builds, from, to, now = Time.now)
periods = builds.map do |b| periods = builds.map do |b|
Period.new(b.public_send(from) || now, b.public_send(to) || now) Period.new(b.public_send(from) || now, b.public_send(to) || now)
end end
......
...@@ -156,7 +156,7 @@ describe Ci::Pipeline, models: true do ...@@ -156,7 +156,7 @@ describe Ci::Pipeline, models: true do
pipeline.reload pipeline.reload
expect(pipeline.duration).to eq(40) expect(pipeline.duration).to eq(40)
expect(pipeline.pending_duration).to eq(25) expect(pipeline.pending_duration).to eq(45)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment