ActiveRecord::StaleObjectError: Attempted to update a stale object: Ci::Build
This commit is contained in:
parent
8d739237de
commit
3494cdfecb
2 changed files with 21 additions and 7 deletions
|
@ -38,11 +38,15 @@ module Ci
|
||||||
begin
|
begin
|
||||||
# In case when 2 runners try to assign the same build, second runner will be declined
|
# In case when 2 runners try to assign the same build, second runner will be declined
|
||||||
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
|
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
|
||||||
|
begin
|
||||||
build.runner_id = runner.id
|
build.runner_id = runner.id
|
||||||
build.run!
|
build.run!
|
||||||
register_success(build)
|
register_success(build)
|
||||||
|
|
||||||
return Result.new(build, true)
|
return Result.new(build, true)
|
||||||
|
rescue Ci::Build::MissingDependenciesError
|
||||||
|
build.drop!(:missing_dependency_failure)
|
||||||
|
end
|
||||||
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
|
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
|
||||||
# We are looping to find another build that is not conflicting
|
# We are looping to find another build that is not conflicting
|
||||||
# It also indicates that this build can be picked and passed to runner.
|
# It also indicates that this build can be picked and passed to runner.
|
||||||
|
@ -54,9 +58,6 @@ module Ci
|
||||||
# we still have to return 409 in the end,
|
# we still have to return 409 in the end,
|
||||||
# to make sure that this is properly handled by runner.
|
# to make sure that this is properly handled by runner.
|
||||||
valid = false
|
valid = false
|
||||||
rescue Ci::Build::MissingDependenciesError
|
|
||||||
build.drop!(:missing_dependency_failure)
|
|
||||||
valid = false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,19 @@ module Ci
|
||||||
|
|
||||||
it_behaves_like 'not pick'
|
it_behaves_like 'not pick'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when job object is staled' do
|
||||||
|
let!(:pre_stage_job) { create(:ci_build, :running, pipeline: pipeline, name: 'test', stage_idx: 0) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Ci::Build).to receive(:drop!)
|
||||||
|
.and_raise(ActiveRecord::StaleObjectError.new(pending_job, :drop!))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not drop nor pick' do
|
||||||
|
expect(subject).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'validation is not active' do
|
shared_examples 'validation is not active' do
|
||||||
|
|
Loading…
Reference in a new issue