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
Boxiang Sun
gitlab-ce
Commits
1b0b8b9c
Commit
1b0b8b9c
authored
Feb 28, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change timeout_source to enum
parent
8ffa4809
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
16 deletions
+35
-16
app/models/ci/build.rb
app/models/ci/build.rb
+11
-4
app/presenters/ci/build_presenter.rb
app/presenters/ci/build_presenter.rb
+14
-0
app/serializers/build_details_entity.rb
app/serializers/build_details_entity.rb
+1
-1
db/migrate/20180221022556_add_used_timeout_and_timeout_source_columns_to_ci_builds.rb
...d_used_timeout_and_timeout_source_columns_to_ci_builds.rb
+1
-1
db/schema.rb
db/schema.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+7
-9
No files found.
app/models/ci/build.rb
View file @
1b0b8b9c
...
@@ -93,6 +93,12 @@ module Ci
...
@@ -93,6 +93,12 @@ module Ci
chronic_duration_attr_reader
:used_timeout_human_readable
,
:used_timeout
chronic_duration_attr_reader
:used_timeout_human_readable
,
:used_timeout
enum
timeout_source:
{
unknown_timeout_source:
nil
,
project_timeout_source:
1
,
runner_timeout_source:
2
}
class
<<
self
class
<<
self
# This is needed for url_for to work,
# This is needed for url_for to work,
# as the controller is JobsController
# as the controller is JobsController
...
@@ -123,10 +129,6 @@ module Ci
...
@@ -123,10 +129,6 @@ module Ci
end
end
after_transition
pending: :running
do
|
build
|
after_transition
pending: :running
do
|
build
|
build
.
used_timeout
=
build
.
timeout
build
.
timeout_source
=
build
.
timeout
<
build
.
project
.
build_timeout
?
'runner'
:
'project'
build
.
save!
build
.
run_after_commit
do
build
.
run_after_commit
do
BuildHooksWorker
.
perform_async
(
id
)
BuildHooksWorker
.
perform_async
(
id
)
end
end
...
@@ -160,6 +162,11 @@ module Ci
...
@@ -160,6 +162,11 @@ module Ci
before_transition
any
=>
[
:running
]
do
|
build
|
before_transition
any
=>
[
:running
]
do
|
build
|
build
.
validates_dependencies!
unless
Feature
.
enabled?
(
'ci_disable_validates_dependencies'
)
build
.
validates_dependencies!
unless
Feature
.
enabled?
(
'ci_disable_validates_dependencies'
)
end
end
before_transition
pending: :running
do
|
build
|
build
.
used_timeout
=
build
.
timeout
build
.
timeout_source
=
build
.
timeout
<
build
.
project
.
build_timeout
?
:runner_timeout_source
:
:project_timeout_source
end
end
end
def
detailed_status
(
current_user
)
def
detailed_status
(
current_user
)
...
...
app/presenters/ci/build_presenter.rb
View file @
1b0b8b9c
module
Ci
module
Ci
class
BuildPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
class
BuildPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
TIMEOUT_SOURCES
=
{
unknown_timeout_source:
nil
,
project_timeout_source:
'project'
,
runner_timeout_source:
'runner'
}.
freeze
presents
:build
presents
:build
def
erased_by_user?
def
erased_by_user?
...
@@ -18,6 +25,13 @@ module Ci
...
@@ -18,6 +25,13 @@ module Ci
end
end
end
end
def
timeout_source
return
unless
build
.
timeout_source?
TIMEOUT_SOURCES
[
build
.
timeout_source
.
to_sym
]
||
build
.
timeout_source
end
def
trigger_variables
def
trigger_variables
return
[]
unless
trigger_request
return
[]
unless
trigger_request
...
...
app/serializers/build_details_entity.rb
View file @
1b0b8b9c
...
@@ -7,7 +7,7 @@ class BuildDetailsEntity < JobEntity
...
@@ -7,7 +7,7 @@ class BuildDetailsEntity < JobEntity
expose
:timeout
,
if:
->
(
*
)
{
!
build
.
used_timeout
.
nil?
}
do
|
build
|
expose
:timeout
,
if:
->
(
*
)
{
!
build
.
used_timeout
.
nil?
}
do
|
build
|
{
value:
build
.
used_timeout_human_readable
,
{
value:
build
.
used_timeout_human_readable
,
source:
build
.
timeout_source
}
source:
build
.
present
.
timeout_source
}
end
end
expose
:erased_by
,
if:
->
(
*
)
{
build
.
erased?
},
using:
UserEntity
expose
:erased_by
,
if:
->
(
*
)
{
build
.
erased?
},
using:
UserEntity
...
...
db/migrate/20180221022556_add_used_timeout_and_timeout_source_columns_to_ci_builds.rb
View file @
1b0b8b9c
...
@@ -5,6 +5,6 @@ class AddUsedTimeoutAndTimeoutSourceColumnsToCiBuilds < ActiveRecord::Migration
...
@@ -5,6 +5,6 @@ class AddUsedTimeoutAndTimeoutSourceColumnsToCiBuilds < ActiveRecord::Migration
def
change
def
change
add_column
:ci_builds
,
:used_timeout
,
:integer
add_column
:ci_builds
,
:used_timeout
,
:integer
add_column
:ci_builds
,
:timeout_source
,
:
string
add_column
:ci_builds
,
:timeout_source
,
:
integer
end
end
end
end
db/schema.rb
View file @
1b0b8b9c
...
@@ -312,7 +312,7 @@ ActiveRecord::Schema.define(version: 20180327101207) do
...
@@ -312,7 +312,7 @@ ActiveRecord::Schema.define(version: 20180327101207) do
t
.
boolean
"protected"
t
.
boolean
"protected"
t
.
integer
"failure_reason"
t
.
integer
"failure_reason"
t
.
integer
"used_timeout"
t
.
integer
"used_timeout"
t
.
string
"timeout_source"
t
.
integer
"timeout_source"
end
end
add_index
"ci_builds"
,
[
"artifacts_expire_at"
],
name:
"index_ci_builds_on_artifacts_expire_at"
,
where:
"(artifacts_file <> ''::text)"
,
using: :btree
add_index
"ci_builds"
,
[
"artifacts_expire_at"
],
name:
"index_ci_builds_on_artifacts_expire_at"
,
where:
"(artifacts_file <> ''::text)"
,
using: :btree
...
...
spec/models/ci/build_spec.rb
View file @
1b0b8b9c
...
@@ -2046,20 +2046,18 @@ describe Ci::Build do
...
@@ -2046,20 +2046,18 @@ describe Ci::Build do
end
end
shared_examples
'saves data on transition'
do
shared_examples
'saves data on transition'
do
it
'saves used_timeout and timeout_source on transition'
do
it
'saves used_timeout'
do
expect
(
job
.
used_timeout
).
to
be_nil
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
used_timeout
}.
from
(
nil
).
to
(
expected_timeout
)
expect
(
job
.
timeout_source
).
to
be_nil
end
job
.
run!
expect
(
job
.
used_timeout
).
to
eq
(
expected_timeout
)
it
'saves timeout_source'
do
expect
(
job
.
timeout_source
).
to
eq
(
expected_timeout_source
)
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
timeout_source
}.
from
(
'unknown_timeout_source'
).
to
(
expected_timeout_source
)
end
end
end
end
context
'when runner timeout overrides project timeout'
do
context
'when runner timeout overrides project timeout'
do
let
(
:expected_timeout
)
{
900
}
let
(
:expected_timeout
)
{
900
}
let
(
:expected_timeout_source
)
{
'
Runner
'
}
let
(
:expected_timeout_source
)
{
'
runner_timeout_source
'
}
before
do
before
do
runner
.
maximum_job_timeout
=
900
runner
.
maximum_job_timeout
=
900
...
@@ -2071,7 +2069,7 @@ describe Ci::Build do
...
@@ -2071,7 +2069,7 @@ describe Ci::Build do
context
"when runner timeout doesn't override project timeout"
do
context
"when runner timeout doesn't override project timeout"
do
let
(
:expected_timeout
)
{
1800
}
let
(
:expected_timeout
)
{
1800
}
let
(
:expected_timeout_source
)
{
'
Project
'
}
let
(
:expected_timeout_source
)
{
'
project_timeout_source
'
}
before
do
before
do
runner
.
maximum_job_timeout
=
3600
runner
.
maximum_job_timeout
=
3600
...
...
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