diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-20 13:30:05 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-20 13:30:48 +0200 |
commit | bbdc35717c1ba08630f5b2ae59a333a81941b181 (patch) | |
tree | ea5532fa6c1a794e03aaa371441cfe7a0af42162 /app | |
parent | e389507650769304bd61f7a82431cc6c07feb364 (diff) | |
download | gitlab-ce-bbdc35717c1ba08630f5b2ae59a333a81941b181.tar.gz |
Implement method that updates a stage status
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/stage.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index c163d047127..066903ddc5b 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -3,6 +3,7 @@ module Ci extend Ci::Model include Importable include HasStatus + include Gitlab::OptimisticLocking enumerate_status! @@ -15,5 +16,51 @@ module Ci validates :project, presence: true, unless: :importing? validates :pipeline, presence: true, unless: :importing? validates :name, presence: true, unless: :importing? + + state_machine :status, initial: :created do + event :enqueue do + transition created: :pending + transition [:success, :failed, :canceled, :skipped] => :running + end + + event :run do + transition any - [:running] => :running + end + + event :skip do + transition any - [:skipped] => :skipped + end + + event :drop do + transition any - [:failed] => :failed + end + + event :succeed do + transition any - [:success] => :success + end + + event :cancel do + transition any - [:canceled] => :canceled + end + + event :block do + transition any - [:manual] => :manual + end + end + + def update! + retry_optimistic_lock(self) do + case commit_statuses.latest.status + when 'pending' then enqueue + when 'running' then run + when 'success' then succeed + when 'failed' then drop + when 'canceled' then cancel + when 'manual' then block + when 'skipped' then skip + else skip + end + end + end end end |