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