Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
db923d4a5870
Commit
204fdcb1
authored
Oct 13, 2016
by
Grzegorz Bizon
Browse files
Add build success worker that runs asynchronously
parent
3c502ebe5e6f
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/ci/build.rb
View file @
db923d4a
...
...
@@ -76,25 +76,22 @@ def retry(build, user = nil)
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 @
db923d4a
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 @
db923d4a
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