BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3a68c989
Commit
3a68c989
authored
Sep 06, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just use module because there's nothing to save, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_14992064
parent
b92c75ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
18 deletions
+14
-18
pipeline_duration.rb
lib/gitlab/ci/pipeline_duration.rb
+10
-14
pipeline_duration_spec.rb
spec/lib/gitlab/ci/pipeline_duration_spec.rb
+4
-4
No files found.
lib/gitlab/ci/pipeline_duration.rb
View file @
3a68c989
...
...
@@ -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?
...
...
spec/lib/gitlab/ci/pipeline_duration_spec.rb
View file @
3a68c989
require
'spec_helper'
describe
Gitlab
::
Ci
::
PipelineDuration
do
let
(
:calculat
or
)
{
create_calculator
(
data
)
}
let
(
:calculat
ed_duration
)
{
calculate
(
data
)
}
shared_examples
'calculating duration'
do
it
do
expect
(
calculat
or
.
duration
).
to
eq
(
duration
)
expect
(
calculat
ed_
duration
).
to
eq
(
duration
)
end
end
...
...
@@ -105,11 +105,11 @@ describe Gitlab::Ci::PipelineDuration do
it_behaves_like
'calculating duration'
end
def
c
reate_calculator
(
data
)
def
c
alculate
(
data
)
periods
=
data
.
shuffle
.
map
do
|
(
first
,
last
)
|
Gitlab
::
Ci
::
PipelineDuration
::
Period
.
new
(
first
,
last
)
end
Gitlab
::
Ci
::
PipelineDuration
.
new
(
periods
)
Gitlab
::
Ci
::
PipelineDuration
.
from_periods
(
periods
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment