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
21fdc1ed
Commit
21fdc1ed
authored
Aug 10, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup the use of duration and optimize some queries
parent
831b6c8f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
50 deletions
+39
-50
time_helper.rb
app/helpers/time_helper.rb
+3
-19
pipeline.rb
app/models/ci/pipeline.rb
+5
-5
commit_status.rb
app/models/commit_status.rb
+7
-7
statuseable.rb
app/models/concerns/statuseable.rb
+10
-5
_build.html.haml
app/views/admin/builds/_build.html.haml
+1
-1
_build.html.haml
app/views/projects/ci/builds/_build.html.haml
+1
-1
_pipeline.html.haml
app/views/projects/ci/pipelines/_pipeline.html.haml
+2
-2
_info.html.haml
app/views/projects/pipelines/_info.html.haml
+2
-2
time_helper_spec.rb
spec/helpers/time_helper_spec.rb
+8
-8
No files found.
app/helpers/time_helper.rb
View file @
21fdc1ed
...
...
@@ -15,25 +15,9 @@ module TimeHelper
"
#{
from
.
to_s
(
:short
)
}
-
#{
to
.
to_s
(
:short
)
}
"
end
def
duration_in_numbers
(
finished_at
,
started_at
)
interval
=
interval_in_seconds
(
started_at
,
finished_at
)
def
duration_in_numbers
(
duration
)
time_format
=
duration
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
duration_in_numbers_from_interval
(
interval
)
end
def
duration_in_numbers_from_interval
(
interval
)
time_format
=
interval
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
Time
.
at
(
interval
).
utc
.
strftime
(
time_format
)
end
private
def
interval_in_seconds
(
started_at
,
finished_at
=
nil
)
if
started_at
&&
finished_at
finished_at
.
to_i
-
started_at
.
to_i
elsif
started_at
Time
.
now
.
to_i
-
started_at
.
to_i
end
Time
.
at
(
duration
).
utc
.
strftime
(
time_format
)
end
end
app/models/ci/pipeline.rb
View file @
21fdc1ed
...
...
@@ -34,6 +34,10 @@ module Ci
CommitStatus
.
where
(
pipeline:
pluck
(
:id
)).
stages
end
def
self
.
duration
where
.
not
(
duration:
nil
).
pluck
(
:duration
).
inject
(
0
,
&
:
+
)
end
def
project_id
project
.
id
end
...
...
@@ -213,10 +217,6 @@ module Ci
]
end
def
wall_clock_duration
finished_at
.
to_i
-
started_at
.
to_i
if
finished_at
&&
started_at
end
private
def
build_builds_for_stages
(
stages
,
user
,
status
,
trigger_request
)
...
...
@@ -240,7 +240,7 @@ module Ci
end
self
.
started_at
=
statuses
.
started_at
self
.
finished_at
=
statuses
.
finished_at
self
.
duration
=
statuses
.
latest
.
duration
self
.
duration
=
calculate_duration
.
to_i
save
end
...
...
app/models/commit_status.rb
View file @
21fdc1ed
...
...
@@ -21,6 +21,7 @@ class CommitStatus < ActiveRecord::Base
where
(
id:
max_id
.
group
(
:name
,
:commit_id
))
end
scope
:retried
,
->
{
where
.
not
(
id:
latest
)
}
scope
:ordered
,
->
{
order
(
:name
)
}
scope
:ignored
,
->
{
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
}
...
...
@@ -83,18 +84,17 @@ class CommitStatus < ActiveRecord::Base
end
end
def
self
.
duration
select
(
:started_at
,
:finished_at
).
all
.
map
(
&
:duration
).
compact
.
inject
(
0
,
&
:
+
)
end
def
ignored?
allow_failure?
&&
(
failed?
||
canceled?
)
end
def
duration
duration
=
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
now
-
started_at
end
duration
calculate_duration
end
def
stuck?
...
...
app/models/concerns/statuseable.rb
View file @
21fdc1ed
...
...
@@ -31,11 +31,6 @@ module Statuseable
all
.
pluck
(
self
.
status_sql
).
first
end
def
duration
duration_array
=
all
.
map
(
&
:duration
).
compact
duration_array
.
reduce
(:
+
)
end
def
started_at
all
.
minimum
(
:started_at
)
end
...
...
@@ -78,4 +73,14 @@ module Statuseable
def
complete?
canceled?
||
success?
||
failed?
end
private
def
calculate_duration
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
now
-
started_at
end
end
end
app/views/admin/builds/_build.html.haml
View file @
21fdc1ed
...
...
@@ -51,7 +51,7 @@
-
if
build
.
duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
(
build
.
finished_at
,
build
.
started_at
)
=
duration_in_numbers
(
build
.
duration
)
-
if
build
.
finished_at
%p
.finished-at
...
...
app/views/projects/ci/builds/_build.html.haml
View file @
21fdc1ed
...
...
@@ -63,7 +63,7 @@
-
if
build
.
duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
(
build
.
finished_at
,
build
.
started_at
)
=
duration_in_numbers
(
build
.
duration
)
-
if
build
.
finished_at
%p
.finished-at
=
icon
(
"calendar"
)
...
...
app/views/projects/ci/pipelines/_pipeline.html.haml
View file @
21fdc1ed
...
...
@@ -46,10 +46,10 @@
\-
%td
-
if
pipeline
.
wall_clock_
duration
-
if
pipeline
.
duration
%p
.duration
=
custom_icon
(
"icon_timer"
)
=
duration_in_numbers
_from_interval
(
pipeline
.
wall_clock_
duration
)
=
duration_in_numbers
(
pipeline
.
duration
)
-
if
pipeline
.
finished_at
%p
.finished-at
=
icon
(
"calendar"
)
...
...
app/views/projects/pipelines/_info.html.haml
View file @
21fdc1ed
...
...
@@ -7,9 +7,9 @@
-
if
@pipeline
.
ref
for
=
link_to
@pipeline
.
ref
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
@pipeline
.
ref
),
class:
"monospace"
-
if
@pipeline
.
wall_clock_
duration
-
if
@pipeline
.
duration
in
=
time_interval_in_words
(
@pipeline
.
wall_clock_
duration
)
=
time_interval_in_words
(
@pipeline
.
duration
)
.pull-right
=
link_to
namespace_project_pipeline_path
(
@project
.
namespace
,
@project
,
@pipeline
),
class:
"ci-status ci-
#{
@pipeline
.
status
}
"
do
...
...
spec/helpers/time_helper_spec.rb
View file @
21fdc1ed
...
...
@@ -19,16 +19,16 @@ describe TimeHelper do
describe
"#duration_in_numbers"
do
it
"returns minutes and seconds"
do
duration
_in_number
s
=
{
[
100
,
0
]
=>
"01:40"
,
[
121
,
0
]
=>
"02:01"
,
[
3721
,
0
]
=>
"01:02:01"
,
[
0
,
0
]
=>
"00:00"
,
[
nil
,
Time
.
now
.
to_i
-
42
]
=>
"00:42"
duration
s_and_expectation
s
=
{
100
=>
"01:40"
,
121
=>
"02:01"
,
3721
=>
"01:02:01"
,
0
=>
"00:00"
,
42
=>
"00:42"
}
duration
_in_numbers
.
each
do
|
interval
,
expectation
|
expect
(
duration_in_numbers
(
*
interval
)).
to
eq
(
expectation
)
duration
s_and_expectations
.
each
do
|
duration
,
expectation
|
expect
(
duration_in_numbers
(
duration
)).
to
eq
(
expectation
)
end
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