Commit fafc5a17 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Perform CI build hooks asynchronously using worker

parent 2461e109
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|
......
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment