diff options
-rw-r--r-- | app/models/ci/stage.rb | 2 | ||||
-rw-r--r-- | app/workers/stage_update_worker.rb | 4 | ||||
-rw-r--r-- | spec/models/ci/stage_spec.rb | 8 |
3 files changed, 8 insertions, 6 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index b1cca06abaa..cd2f1dd3509 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -50,7 +50,7 @@ module Ci end end - def update! + def update_status retry_optimistic_lock(self) do case commit_statuses.latest.status when 'pending' then enqueue diff --git a/app/workers/stage_update_worker.rb b/app/workers/stage_update_worker.rb index 1d6f23305d6..eef0b11e70b 100644 --- a/app/workers/stage_update_worker.rb +++ b/app/workers/stage_update_worker.rb @@ -3,6 +3,8 @@ class StageUpdateWorker include PipelineQueue def perform(stage_id) - Ci::Stage.find_by(id: stage_id)&.update! + Ci::Stage.find_by(id: stage_id).try do |stage| + stage.update_status + end end end diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index 3dc00017a2c..d5c66598451 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -40,7 +40,7 @@ describe Ci::Stage, :models do end end - describe 'update!' do + describe 'update_status' do context 'when stage objects needs to be updated' do before do create(:ci_build, :success, stage_id: stage.id) @@ -48,7 +48,7 @@ describe Ci::Stage, :models do end it 'updates stage status correctly' do - expect { stage.update! } + expect { stage.update_status } .to change { stage.reload.status } .to 'running' end @@ -56,7 +56,7 @@ describe Ci::Stage, :models do context 'when stage is skipped' do it 'updates status to skipped' do - expect { stage.update! } + expect { stage.update_status } .to change { stage.reload.status } .to 'skipped' end @@ -70,7 +70,7 @@ describe Ci::Stage, :models do it 'retries a lock to update a stage status' do stage.lock_version = 100 - stage.update! + stage.update_status expect(stage.reload).to be_failed end |