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
Jérome Perrin
gitlab-ce
Commits
204fdcb1
Commit
204fdcb1
authored
Oct 13, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add build success worker that runs asynchronously
parent
fafc5a17
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
12 deletions
+61
-12
app/models/ci/build.rb
app/models/ci/build.rb
+9
-12
app/workers/build_success_worker.rb
app/workers/build_success_worker.rb
+27
-0
spec/workers/build_success_worker_spec.rb
spec/workers/build_success_worker_spec.rb
+25
-0
No files found.
app/models/ci/build.rb
View file @
204fdcb1
...
...
@@ -76,25 +76,22 @@ module Ci
state_machine
:status
do
after_transition
pending: :running
do
|
build
|
build
.
run_after_commit
{
BuildHooksWorker
.
perform_async
(
id
)
}
build
.
run_after_commit
do
BuildHooksWorker
.
perform_async
(
id
)
end
end
after_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
build
|
build
.
update_coverage
build
.
run_after_commit
{
BuildHooksWorker
.
perform_async
(
id
)
}
build
.
run_after_commit
do
BuildHooksWorker
.
perform_async
(
id
)
end
end
after_transition
any
=>
[
:success
]
do
|
build
|
if
build
.
environment
.
present?
service
=
CreateDeploymentService
.
new
(
build
.
project
,
build
.
user
,
environment:
build
.
environment
,
sha:
build
.
sha
,
ref:
build
.
ref
,
tag:
build
.
tag
,
options:
build
.
options
.
to_h
[
:environment
],
variables:
build
.
variables
)
service
.
execute
(
build
)
build
.
run_after_commit
do
BuildSuccessWorker
.
perform_async
(
id
)
end
end
end
...
...
app/workers/build_success_worker.rb
0 → 100644
View file @
204fdcb1
class
BuildSuccessWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
def
perform
(
build_id
)
Ci
::
Build
.
find_by
(
id:
build_id
).
try
do
|
build
|
perform_deloyment
(
build
)
end
end
private
def
perform_deloyment
(
build
)
return
if
build
.
environment
.
blank?
service
=
CreateDeploymentService
.
new
(
build
.
project
,
build
.
user
,
environment:
build
.
environment
,
sha:
build
.
sha
,
ref:
build
.
ref
,
tag:
build
.
tag
,
options:
build
.
options
.
to_h
[
:environment
],
variables:
build
.
variables
)
service
.
execute
(
build
)
end
end
spec/workers/build_success_worker_spec.rb
0 → 100644
View file @
204fdcb1
require
'spec_helper'
describe
BuildSuccessWorker
do
describe
'#perform'
do
context
'when build exists'
do
context
'when build belogs to the environment'
do
let!
(
:build
)
{
create
(
:ci_build
,
environment:
'production'
)
}
it
'executes deployment service'
do
expect_any_instance_of
(
CreateDeploymentService
)
.
to
receive
(
:execute
)
described_class
.
new
.
perform
(
build
.
id
)
end
end
end
context
'when build does not exist'
do
it
'does not raise exception'
do
expect
{
described_class
.
new
.
perform
(
123
)
}
.
not_to
raise_error
end
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