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
1
Merge Requests
1
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
nexedi
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
Gitlab
module
Ci
module
Ci
class
PipelineDuration
class
PipelineDuration
Segment
Struct
=
Struct
.
new
(
:first
,
:last
)
Period
Struct
=
Struct
.
new
(
:first
,
:last
)
class
Segment
<
SegmentStruct
class
Period
<
SegmentStruct
def
duration
def
duration
last
-
first
last
-
first
end
end
...
@@ -11,34 +11,34 @@ module Gitlab
...
@@ -11,34 +11,34 @@ module Gitlab
def
self
.
from_builds
(
builds
)
def
self
.
from_builds
(
builds
)
now
=
Time
.
now
now
=
Time
.
now
segment
s
=
builds
.
map
do
|
b
|
period
s
=
builds
.
map
do
|
b
|
Segment
.
new
(
b
.
started_at
||
now
,
b
.
finished_at
||
now
)
Period
.
new
(
b
.
started_at
||
now
,
b
.
finished_at
||
now
)
end
end
new
(
segment
s
)
new
(
period
s
)
end
end
attr_reader
:duration
,
:pending_duration
attr_reader
:duration
,
:pending_duration
def
initialize
(
segment
s
)
def
initialize
(
period
s
)
process
(
segment
s
.
sort_by
(
&
:first
))
process
(
period
s
.
sort_by
(
&
:first
))
end
end
private
private
def
process
(
segment
s
)
def
process
(
period
s
)
merged
=
process_
segments
(
segment
s
)
merged
=
process_
periods
(
period
s
)
@duration
=
process_duration
(
merged
)
@duration
=
process_duration
(
merged
)
@pending_duration
=
process_pending_duration
(
merged
,
@duration
)
@pending_duration
=
process_pending_duration
(
merged
,
@duration
)
end
end
def
process_
segments
(
segment
s
)
def
process_
periods
(
period
s
)
if
segment
s
.
empty?
if
period
s
.
empty?
segment
s
period
s
else
else
segments
.
drop
(
1
).
inject
([
segment
s
.
first
])
do
|
result
,
current
|
periods
.
drop
(
1
).
inject
([
period
s
.
first
])
do
|
result
,
current
|
merged
=
try_merge_
segment
(
result
.
last
,
current
)
merged
=
try_merge_
period
(
result
.
last
,
current
)
if
merged
if
merged
result
[
-
1
]
=
merged
result
[
-
1
]
=
merged
...
@@ -50,22 +50,22 @@ module Gitlab
...
@@ -50,22 +50,22 @@ module Gitlab
end
end
end
end
def
try_merge_
segment
(
previous
,
current
)
def
try_merge_
period
(
previous
,
current
)
if
current
.
first
<=
previous
.
last
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
end
end
def
process_duration
(
segment
s
)
def
process_duration
(
period
s
)
segments
.
inject
(
0
)
do
|
result
,
seg
|
periods
.
inject
(
0
)
do
|
result
,
per
|
result
+
seg
.
duration
result
+
per
.
duration
end
end
end
end
def
process_pending_duration
(
segment
s
,
duration
)
def
process_pending_duration
(
period
s
,
duration
)
return
0
if
segment
s
.
empty?
return
0
if
period
s
.
empty?
total
=
segments
.
last
.
last
-
segment
s
.
first
.
first
total
=
periods
.
last
.
last
-
period
s
.
first
.
first
total
-
duration
total
-
duration
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline_duration_spec.rb
View file @
1f6efa35
...
@@ -87,7 +87,7 @@ describe Gitlab::Ci::PipelineDuration do
...
@@ -87,7 +87,7 @@ describe Gitlab::Ci::PipelineDuration do
def
create_calculator
(
data
)
def
create_calculator
(
data
)
segments
=
data
.
shuffle
.
map
do
|
(
first
,
last
)
|
segments
=
data
.
shuffle
.
map
do
|
(
first
,
last
)
|
Gitlab
::
Ci
::
PipelineDuration
::
Segment
.
new
(
first
,
last
)
Gitlab
::
Ci
::
PipelineDuration
::
Period
.
new
(
first
,
last
)
end
end
Gitlab
::
Ci
::
PipelineDuration
.
new
(
segments
)
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