Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
1f6efa35
Commit
1f6efa35
authored
Aug 30, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to periods since it's easier to understand
parent
bd78e6af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
lib/gitlab/ci/pipeline_duration.rb
lib/gitlab/ci/pipeline_duration.rb
+22
-22
spec/lib/gitlab/ci/pipeline_duration_spec.rb
spec/lib/gitlab/ci/pipeline_duration_spec.rb
+1
-1
No files found.
lib/gitlab/ci/pipeline_duration.rb
View file @
1f6efa35
module
Gitlab
module
Ci
class
PipelineDuration
Segment
Struct
=
Struct
.
new
(
:first
,
:last
)
class
Segment
<
SegmentStruct
Period
Struct
=
Struct
.
new
(
:first
,
:last
)
class
Period
<
SegmentStruct
def
duration
last
-
first
end
...
...
@@ -11,34 +11,34 @@ module Gitlab
def
self
.
from_builds
(
builds
)
now
=
Time
.
now
segment
s
=
builds
.
map
do
|
b
|
Segment
.
new
(
b
.
started_at
||
now
,
b
.
finished_at
||
now
)
period
s
=
builds
.
map
do
|
b
|
Period
.
new
(
b
.
started_at
||
now
,
b
.
finished_at
||
now
)
end
new
(
segment
s
)
new
(
period
s
)
end
attr_reader
:duration
,
:pending_duration
def
initialize
(
segment
s
)
process
(
segment
s
.
sort_by
(
&
:first
))
def
initialize
(
period
s
)
process
(
period
s
.
sort_by
(
&
:first
))
end
private
def
process
(
segment
s
)
merged
=
process_
segments
(
segment
s
)
def
process
(
period
s
)
merged
=
process_
periods
(
period
s
)
@duration
=
process_duration
(
merged
)
@pending_duration
=
process_pending_duration
(
merged
,
@duration
)
end
def
process_
segments
(
segment
s
)
if
segment
s
.
empty?
segment
s
def
process_
periods
(
period
s
)
if
period
s
.
empty?
period
s
else
segments
.
drop
(
1
).
inject
([
segment
s
.
first
])
do
|
result
,
current
|
merged
=
try_merge_
segment
(
result
.
last
,
current
)
periods
.
drop
(
1
).
inject
([
period
s
.
first
])
do
|
result
,
current
|
merged
=
try_merge_
period
(
result
.
last
,
current
)
if
merged
result
[
-
1
]
=
merged
...
...
@@ -50,22 +50,22 @@ module Gitlab
end
end
def
try_merge_
segment
(
previous
,
current
)
def
try_merge_
period
(
previous
,
current
)
if
current
.
first
<=
previous
.
last
Segment
.
new
(
previous
.
first
,
[
previous
.
last
,
current
.
last
].
max
)
Period
.
new
(
previous
.
first
,
[
previous
.
last
,
current
.
last
].
max
)
end
end
def
process_duration
(
segment
s
)
segments
.
inject
(
0
)
do
|
result
,
seg
|
result
+
seg
.
duration
def
process_duration
(
period
s
)
periods
.
inject
(
0
)
do
|
result
,
per
|
result
+
per
.
duration
end
end
def
process_pending_duration
(
segment
s
,
duration
)
return
0
if
segment
s
.
empty?
def
process_pending_duration
(
period
s
,
duration
)
return
0
if
period
s
.
empty?
total
=
segments
.
last
.
last
-
segment
s
.
first
.
first
total
=
periods
.
last
.
last
-
period
s
.
first
.
first
total
-
duration
end
end
...
...
spec/lib/gitlab/ci/pipeline_duration_spec.rb
View file @
1f6efa35
...
...
@@ -87,7 +87,7 @@ describe Gitlab::Ci::PipelineDuration do
def
create_calculator
(
data
)
segments
=
data
.
shuffle
.
map
do
|
(
first
,
last
)
|
Gitlab
::
Ci
::
PipelineDuration
::
Segment
.
new
(
first
,
last
)
Gitlab
::
Ci
::
PipelineDuration
::
Period
.
new
(
first
,
last
)
end
Gitlab
::
Ci
::
PipelineDuration
.
new
(
segments
)
...
...
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