Commit eae604e6 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'backstage/gb/after-save-asynchronous-job-hooks' into 'master'

Do not fire synchronous hooks when creating a job

Closes #35286

See merge request !13734
parents 6752a3bb 3c2bcf25
...@@ -46,7 +46,10 @@ module Ci ...@@ -46,7 +46,10 @@ module Ci
before_save :ensure_token before_save :ensure_token
before_destroy { unscoped_project } before_destroy { unscoped_project }
after_create :execute_hooks after_create do |build|
run_after_commit { BuildHooksWorker.perform_async(build.id) }
end
after_commit :update_project_statistics_after_save, on: [:create, :update] after_commit :update_project_statistics_after_save, on: [:create, :update]
after_commit :update_project_statistics, on: :destroy after_commit :update_project_statistics, on: :destroy
......
---
title: Fire hooks asynchronously when creating a new job to improve performance
merge_request: 13734
author:
type: changed
...@@ -35,7 +35,10 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps ...@@ -35,7 +35,10 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps
end end
step 'pages are deployed' do step 'pages are deployed' do
pipeline = @project.pipelines.create(ref: 'HEAD', sha: @project.commit('HEAD').sha) pipeline = @project.pipelines.create(ref: 'HEAD',
sha: @project.commit('HEAD').sha,
source: :push)
build = build(:ci_build, build = build(:ci_build,
project: @project, project: @project,
pipeline: pipeline, pipeline: pipeline,
...@@ -43,6 +46,7 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps ...@@ -43,6 +46,7 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps
artifacts_file: fixture_file_upload(Rails.root + 'spec/fixtures/pages.zip'), artifacts_file: fixture_file_upload(Rails.root + 'spec/fixtures/pages.zip'),
artifacts_metadata: fixture_file_upload(Rails.root + 'spec/fixtures/pages.zip.meta') artifacts_metadata: fixture_file_upload(Rails.root + 'spec/fixtures/pages.zip.meta')
) )
result = ::Projects::UpdatePagesService.new(@project, build).execute result = ::Projects::UpdatePagesService.new(@project, build).execute
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
end end
......
...@@ -21,6 +21,16 @@ describe Ci::Build do ...@@ -21,6 +21,16 @@ describe Ci::Build do
it { is_expected.to respond_to(:has_trace?) } it { is_expected.to respond_to(:has_trace?) }
it { is_expected.to respond_to(: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 describe '.manual_actions' do
let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) } let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) }
let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) } let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) }
......
...@@ -78,6 +78,8 @@ module CycleAnalyticsHelpers ...@@ -78,6 +78,8 @@ module CycleAnalyticsHelpers
@dummy_pipeline ||= @dummy_pipeline ||=
Ci::Pipeline.new( Ci::Pipeline.new(
sha: project.repository.commit('master').sha, sha: project.repository.commit('master').sha,
ref: 'master',
source: :push,
project: project) project: project)
end end
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe BuildFinishedWorker do describe BuildFinishedWorker do
describe '#perform' do describe '#perform' do
context 'when build exists' do context 'when build exists' do
let(:build) { create(:ci_build) } let!(:build) { create(:ci_build) }
it 'calculates coverage and calls hooks' do it 'calculates coverage and calls hooks' do
expect(BuildCoverageWorker) expect(BuildCoverageWorker)
......
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