Commit 6c740324 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not process jobs when pipeline activity limit exceeded

parent 4adc2698
......@@ -5,6 +5,7 @@ module Ci
include Importable
include AfterCommitQueue
include Presentable
include Gitlab::OptimisticLocking
prepend ::EE::Ci::Pipeline
......@@ -287,7 +288,7 @@ module Ci
end
def cancel_running
Gitlab::OptimisticLocking.retry_lock(cancelable_statuses) do |cancelable|
retry_optimistic_lock(cancelable_statuses) do |cancelable|
cancelable.find_each do |job|
yield(job) if block_given?
job.cancel
......@@ -431,7 +432,7 @@ module Ci
end
def update_status
Gitlab::OptimisticLocking.retry_lock(self) do
retry_optimistic_lock(self) do
case latest_builds_status
when 'pending' then enqueue
when 'running' then run
......
......@@ -18,18 +18,9 @@ module EE
def perform!
return unless @limit.exceeded?
@pipeline.cancel_running
retry_optimistic_lock(@pipeline) do
@pipeline.drop!(:activity_limit_exceeded)
end
# TODO, should we invalidate the pipeline
# while it is already persisted?
#
# Should we show info in the UI or alert/warning?
#
error(@limit.message)
end
def break?
......
......@@ -6,18 +6,13 @@ describe EE::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
set(:user) { create(:user) }
let(:command) do
double('command', project: project,
current_user: user)
double('command', project: project, current_user: user)
end
let(:pipeline) do
create(:ci_pipeline, project: project)
end
before do
create(:ci_build, pipeline: pipeline)
end
let(:step) { described_class.new(pipeline, command) }
context 'when active pipelines limit is exceeded' do
......@@ -38,11 +33,6 @@ describe EE::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
expect(pipeline).to be_persisted
end
it 'cancels all pipeline jobs' do
expect(pipeline.statuses).not_to be_empty
expect(pipeline.statuses).to all(be_canceled)
end
it 'breaks the chain' do
expect(step.break?).to be true
end
......
......@@ -37,13 +37,13 @@ describe Ci::CreatePipelineService, '#execute' do
create(:ci_pipeline, project: project, status: 'running')
end
it 'drops the pipeline and cancels all jobs' do
it 'drops the pipeline and does not process jobs' do
pipeline = create_pipeline!
expect(pipeline).to be_persisted
expect(pipeline).to be_failed
expect(pipeline.statuses).not_to be_empty
expect(pipeline.statuses).to all(be_canceled)
expect(pipeline.statuses).to all(be_created)
expect(pipeline.activity_limit_exceeded?).to be true
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