summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-22 10:57:52 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-22 10:57:52 +0200
commit086f0351df9f013b4b0f3f80f7ab5d18be0d1733 (patch)
treef48f8f70e0e8842f16ef3ce5cd7577789c04641a
parent6509833cfa211804048ec4711572e3b44a5be21c (diff)
downloadgitlab-ce-086f0351df9f013b4b0f3f80f7ab5d18be0d1733.tar.gz
Do not fire synrchonous hooks when creating a job
Fire asynchronous hooks instead.
-rw-r--r--app/models/ci/build.rb5
-rw-r--r--spec/models/ci/build_spec.rb10
2 files changed, 14 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 4692fb5644a..936e3c83dfd 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -46,7 +46,10 @@ module Ci
before_save :ensure_token
before_destroy { unscoped_project }
- after_create :execute_hooks
+ after_create do |build|
+ BuildHooksWorker.perform_async(build.id)
+ end
+
after_commit :update_project_statistics_after_save, on: [:create, :update]
after_commit :update_project_statistics, on: :destroy
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 767f0ad9e65..4f77f0d85cd 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -21,6 +21,16 @@ describe Ci::Build do
it { is_expected.to respond_to(:has_trace?) }
it { is_expected.to respond_to(:trace) }
+ describe 'callbacks' do
+ context 'when running after_create callback' do
+ it 'triggers asynchronous build hooks worker' do
+ expect(BuildHooksWorker).to receive(:perform_async)
+
+ create(:ci_build)
+ end
+ end
+ end
+
describe '.manual_actions' do
let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) }
let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) }