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
31af6be0
Commit
31af6be0
authored
Jan 19, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs
parent
1c7eb963
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
10 deletions
+39
-10
app/models/ci/runner.rb
app/models/ci/runner.rb
+9
-3
app/services/ci/update_build_queue_service.rb
app/services/ci/update_build_queue_service.rb
+1
-1
lib/api/helpers.rb
lib/api/helpers.rb
+1
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+28
-5
No files found.
app/models/ci/runner.rb
View file @
31af6be0
...
...
@@ -22,7 +22,7 @@ module Ci
scope
:online
,
->
()
{
where
(
'contacted_at > ?'
,
LAST_CONTACT_TIME
)
}
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
after_save
:tick_runner_queue
after_save
:tick_runner_queue
,
if: :form_editable_changed?
scope
:owned_or_shared
,
->
(
project_id
)
do
joins
(
'LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'
)
...
...
@@ -126,14 +126,14 @@ module Ci
end
def
tick_runner_queue
new_update
=
Time
.
new
.
inspect
new_update
=
SecureRandom
.
hex
Gitlab
::
Redis
.
with
{
|
redis
|
redis
.
set
(
runner_queue_key
,
new_update
,
ex:
RUNNER_QUEUE_EXPIRY_TIME
)
}
new_update
end
def
ensure_runner_queue_value
Gitlab
::
Redis
.
with
do
|
redis
|
value
=
Time
.
new
.
inspect
value
=
SecureRandom
.
hex
redis
.
set
(
runner_queue_key
,
value
,
ex:
RUNNER_QUEUE_EXPIRY_TIME
,
nx:
true
)
redis
.
get
(
runner_queue_key
)
end
...
...
@@ -149,6 +149,12 @@ module Ci
"runner:build_queue:
#{
self
.
token
}
"
end
def
form_editable_changed?
FORM_EDITABLE
.
any?
do
|
editable
|
public_send
(
"
#{
editable
}
_changed?"
)
end
end
def
tag_constraints
unless
has_tags?
||
run_untagged?
errors
.
add
(
:tags_list
,
...
...
app/services/ci/update_build_queue_service.rb
View file @
31af6be0
module
Ci
class
UpdateBuildQueueService
def
execute
(
build
)
build
.
project
.
runners
.
select
do
|
runner
|
build
.
project
.
runners
.
each
do
|
runner
|
if
runner
.
can_pick?
(
build
)
runner
.
tick_runner_queue
end
...
...
lib/api/helpers.rb
View file @
31af6be0
...
...
@@ -226,7 +226,7 @@ module API
end
def
render_api_error!
(
message
,
status
)
error!
({
'message'
=>
message
},
status
,
header
)
error!
({
'message'
=>
message
},
status
)
end
def
handle_api_exception
(
exception
)
...
...
spec/models/ci/runner_spec.rb
View file @
31af6be0
...
...
@@ -277,21 +277,44 @@ describe Ci::Runner, models: true do
it
'sets a new last_update value when it is called the first time'
do
last_update
=
runner
.
ensure_runner_queue_value
expect_value_in_redis
(
last_update
)
expect_value_in_redis
.
to
eq
(
last_update
)
end
it
'does not change if it is not expired and called again'
do
last_update
=
runner
.
ensure_runner_queue_value
expect
(
runner
.
ensure_runner_queue_value
).
to
eq
(
last_update
)
expect_value_in_redis
(
last_update
)
expect_value_in_redis
.
to
eq
(
last_update
)
end
def
expect_value_in_redis
(
last_update
)
context
'updates runner queue after changing editable value'
do
let!
(
:last_update
)
{
runner
.
ensure_runner_queue_value
}
before
do
runner
.
update
(
description:
'new runner'
)
end
it
'sets a new last_update value'
do
expect_value_in_redis
.
not_to
eq
(
last_update
)
end
end
context
'does not update runner value after save'
do
let!
(
:last_update
)
{
runner
.
ensure_runner_queue_value
}
before
do
runner
.
touch
end
it
'has an old last_update value'
do
expect_value_in_redis
.
to
eq
(
last_update
)
end
end
def
expect_value_in_redis
Gitlab
::
Redis
.
with
do
|
redis
|
runner_queue_key
=
runner
.
send
(
:runner_queue_key
)
expect
(
redis
.
get
(
runner_queue_key
)).
to
eq
(
last_update
)
expect
(
redis
.
get
(
runner_queue_key
))
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