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
7a109402
Commit
7a109402
authored
Jan 20, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prefer service object over after_save hook
Closes #26921
parent
4b7e8f25
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
23 deletions
+52
-23
app/controllers/admin/runners_controller.rb
app/controllers/admin/runners_controller.rb
+3
-3
app/controllers/projects/runners_controller.rb
app/controllers/projects/runners_controller.rb
+3
-3
app/models/ci/runner.rb
app/models/ci/runner.rb
+0
-8
app/services/ci/update_runner_service.rb
app/services/ci/update_runner_service.rb
+15
-0
lib/ci/api/runners.rb
lib/ci/api/runners.rb
+12
-8
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+1
-1
spec/services/ci/update_runner_service_spec.rb
spec/services/ci/update_runner_service_spec.rb
+18
-0
No files found.
app/controllers/admin/runners_controller.rb
View file @
7a109402
...
...
@@ -13,7 +13,7 @@ class Admin::RunnersController < Admin::ApplicationController
end
def
update
if
@runner
.
update_attributes
(
runner_params
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
runner_params
)
respond_to
do
|
format
|
format
.
js
format
.
html
{
redirect_to
admin_runner_path
(
@runner
)
}
...
...
@@ -31,7 +31,7 @@ class Admin::RunnersController < Admin::ApplicationController
end
def
resume
if
@runner
.
update_attributes
(
active:
true
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
active:
true
)
redirect_to
admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
admin_runners_path
,
alert:
'Runner was not updated.'
...
...
@@ -39,7 +39,7 @@ class Admin::RunnersController < Admin::ApplicationController
end
def
pause
if
@runner
.
update_attributes
(
active:
false
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
active:
false
)
redirect_to
admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
admin_runners_path
,
alert:
'Runner was not updated.'
...
...
app/controllers/projects/runners_controller.rb
View file @
7a109402
...
...
@@ -16,7 +16,7 @@ class Projects::RunnersController < Projects::ApplicationController
end
def
update
if
@runner
.
update_attributes
(
runner_params
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
runner_params
)
redirect_to
runner_path
(
@runner
),
notice:
'Runner was successfully updated.'
else
render
'edit'
...
...
@@ -32,7 +32,7 @@ class Projects::RunnersController < Projects::ApplicationController
end
def
resume
if
@runner
.
update_attributes
(
active:
true
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
active:
true
)
redirect_to
runner_path
(
@runner
),
notice:
'Runner was successfully updated.'
else
redirect_to
runner_path
(
@runner
),
alert:
'Runner was not updated.'
...
...
@@ -40,7 +40,7 @@ class Projects::RunnersController < Projects::ApplicationController
end
def
pause
if
@runner
.
update_attributes
(
active:
false
)
if
Ci
::
UpdateRunnerService
.
new
(
@runner
).
update
(
active:
false
)
redirect_to
runner_path
(
@runner
),
notice:
'Runner was successfully updated.'
else
redirect_to
runner_path
(
@runner
),
alert:
'Runner was not updated.'
...
...
app/models/ci/runner.rb
View file @
7a109402
...
...
@@ -22,8 +22,6 @@ module Ci
scope
:online
,
->
()
{
where
(
'contacted_at > ?'
,
LAST_CONTACT_TIME
)
}
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
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'
)
.
where
(
"ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true"
,
project_id:
project_id
)
...
...
@@ -149,12 +147,6 @@ 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_runner_service.rb
0 → 100644
View file @
7a109402
module
Ci
class
UpdateRunnerService
attr_reader
:runner
def
initialize
(
runner
)
@runner
=
runner
end
def
update
(
params
)
runner
.
update
(
params
).
tap
do
runner
.
tick_runner_queue
end
end
end
end
lib/ci/api/runners.rb
View file @
7a109402
...
...
@@ -28,23 +28,27 @@ module Ci
post
"register"
do
required_attributes!
[
:token
]
attributes
=
attributes_for_keys
(
[
:description
,
:tag_list
,
:run_untagged
,
:locked
]
)
project
=
nil
runner
=
if
runner_registration_token_valid?
# Create shared runner. Requires admin access
Ci
::
Runner
.
create
(
attributes
.
merge
(
is_shared:
true
)
)
Ci
::
Runner
.
new
(
is_shared:
true
)
elsif
project
=
Project
.
find_by
(
runners_token:
params
[
:token
])
# Create a specific runner for project.
project
.
runners
.
create
(
attributes
)
Ci
::
Runner
.
new
end
return
forbidden!
unless
runner
attributes
=
attributes_for_keys
(
[
:description
,
:tag_list
,
:run_untagged
,
:locked
]
).
merge
(
get_runner_version_from_params
||
{})
Ci
::
UpdateRunnerService
.
new
(
runner
).
update
(
attributes
)
# Assign the specific runner for the project
project
.
runners
<<
runner
if
project
if
runner
.
id
runner
.
update
(
get_runner_version_from_params
)
present
runner
,
with:
Entities
::
Runner
else
not_found!
...
...
spec/models/ci/runner_spec.rb
View file @
7a109402
...
...
@@ -291,7 +291,7 @@ describe Ci::Runner, models: true do
let!
(
:last_update
)
{
runner
.
ensure_runner_queue_value
}
before
do
runner
.
update
(
description:
'new runner'
)
Ci
::
UpdateRunnerService
.
new
(
runner
)
.
update
(
description:
'new runner'
)
end
it
'sets a new last_update value'
do
...
...
spec/services/ci/update_runner_service_spec.rb
0 → 100644
View file @
7a109402
require
'spec_helper'
describe
Ci
::
UpdateRunnerService
,
services:
true
do
let
(
:runner
)
{
create
(
:ci_runner
)
}
describe
'#update'
do
before
do
allow
(
runner
).
to
receive
(
:tick_runner_queue
)
described_class
.
new
(
runner
).
update
(
description:
'new runner'
)
end
it
'updates the runner and ticking the queue'
do
expect
(
runner
.
description
).
to
eq
(
'new runner'
)
expect
(
runner
).
to
have_received
(
:tick_runner_queue
)
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