Perform CI build hooks asynchronously using worker
This commit is contained in:
parent
2461e10912
commit
fafc5a1777
3 changed files with 35 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
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 @@ module Ci
|
|||
|
||||
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|
|
||||
|
|
9
app/workers/build_hooks_worker.rb
Normal file
9
app/workers/build_hooks_worker.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
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
|
23
spec/workers/build_hooks_worker_spec.rb
Normal file
23
spec/workers/build_hooks_worker_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
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
|
Loading…
Reference in a new issue