summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-10-17 15:49:57 +0900
committerShinya Maeda <shinya@gitlab.com>2018-10-17 15:49:57 +0900
commitd3446ad9b3ea1d0e813f223f69ce3ed11ae3345b (patch)
tree4f971df4fead768c975e778f1ee045d13d00e5d7
parenta4b04141badb315823419d28ccbd74fe0d4fd7f2 (diff)
downloadgitlab-ce-d3446ad9b3ea1d0e813f223f69ce3ed11ae3345b.tar.gz
Redefine statuses
-rw-r--r--app/models/deployment.rb44
1 files changed, 15 insertions, 29 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index a5ac0f34aea..73689efaecc 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -23,63 +23,49 @@ class Deployment < ActiveRecord::Base
scope :for_environment, -> (environment) { where(environment_id: environment) }
- enum status: HasStatus::STATUSES_ENUM
+ enum status: {
+ created: 0,
+ running: 1,
+ success: 2,
+ failed: 3,
+ canceled: 4
+ }
- state_machine :status, initial: :created do
- event :enqueue do
- transition created: :pending
- transition [:success, :failed, :canceled, :skipped] => :running
- end
+ # Override enum's method to support legacy deployment records that do not have `status` value
+ scope :success, -> () { where('status = (?) OR status IS NULL', statuses[:success]) }
+ state_machine :status, initial: :created do
event :run do
transition any - [:running] => :running
end
- event :skip do
- transition any - [:skipped] => :skipped
+ event :succeed do
+ transition any - [:success] => :success
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
-
- event :delay do
- transition any - [:scheduled] => :scheduled
- end
end
def update_status
retry_optimistic_lock(self) do
case deployable.try(:status)
- when 'created' then nil
- 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 'scheduled' then delay
- when 'skipped', nil then skip
+ when 'skipped', 'canceled' then cancel
else
- raise HasStatus::UnknownStatusError,
- "Unknown status `#{statuses.latest.status}`"
+ # no-op
end
end
end
- # To set legacy deployment status to :success
+ # Override enum's method to support legacy deployment records that do not have `status` value
def success?
return true if status.nil?