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
3c502ebe5e6f
Commit
fafc5a17
authored
Oct 13, 2016
by
Grzegorz Bizon
Browse files
Perform CI build hooks asynchronously using worker
parent
5e1ed15d6cd4
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/ci/build.rb
View file @
3c502ebe
module
Ci
class
Build
<
CommitStatus
include
TokenAuthenticatable
include
AfterCommitQueue
belongs_to
:runner
,
class_name:
'Ci::Runner'
belongs_to
:trigger_request
,
class_name:
'Ci::TriggerRequest'
...
...
@@ -75,12 +76,12 @@ def retry(build, user = nil)
state_machine
:status
do
after_transition
pending: :running
do
|
build
|
build
.
execute_hooks
build
.
run_after_commit
{
BuildHooksWorker
.
perform_async
(
id
)
}
end
after_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
build
|
build
.
update_coverage
build
.
execute_hooks
build
.
run_after_commit
{
BuildHooksWorker
.
perform_async
(
id
)
}
end
after_transition
any
=>
[
:success
]
do
|
build
|
...
...
app/workers/build_hooks_worker.rb
0 → 100644
View file @
3c502ebe
class
BuildHooksWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
def
perform
(
build_id
)
Ci
::
Build
.
find_by
(
id:
build_id
)
.
try
(
:execute_hooks
)
end
end
spec/workers/build_hooks_worker_spec.rb
0 → 100644
View file @
3c502ebe
require
'spec_helper'
describe
BuildHooksWorker
do
describe
'#perform'
do
context
'when build exists'
do
let!
(
:build
)
{
create
(
:ci_build
)
}
it
'calls build hooks'
do
expect_any_instance_of
(
Ci
::
Build
)
.
to
receive
(
:execute_hooks
)
described_class
.
new
.
perform
(
build
.
id
)
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