Just sum all the queuing time, indication for needing more runners
This commit is contained in:
parent
8d96062f23
commit
7aaed299eb
|
@ -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|
|
||||||
|
result + ((job.started_at || now) - (job.queued_at || now))
|
||||||
|
end
|
||||||
|
|
||||||
[running, pending + total - running]
|
[running, pending + queuing]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_builds(builds, from, to)
|
def self.from_builds(builds, from, to, now = Time.now)
|
||||||
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
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue