summaryrefslogtreecommitdiff
path: root/app/models/deployment.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/deployment.rb')
-rw-r--r--app/models/deployment.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index 4a38912db9b..994e69912b6 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -4,6 +4,8 @@ class Deployment < ApplicationRecord
include AtomicInternalId
include IidRoutes
include AfterCommitQueue
+ include UpdatedAtFilterable
+ include Gitlab::Utils::StrongMemoize
belongs_to :project, required: true
belongs_to :environment, required: true
@@ -125,6 +127,12 @@ class Deployment < ApplicationRecord
@scheduled_actions ||= deployable.try(:other_scheduled_actions)
end
+ def playable_build
+ strong_memoize(:playable_build) do
+ deployable.try(:playable?) ? deployable : nil
+ end
+ end
+
def includes_commit?(commit)
return false unless commit
@@ -209,6 +217,23 @@ class Deployment < ApplicationRecord
SQL
end
+ # Changes the status of a deployment and triggers the correspinding state
+ # machine events.
+ def update_status(status)
+ case status
+ when 'running'
+ run
+ when 'success'
+ succeed
+ when 'failed'
+ drop
+ when 'canceled'
+ cancel
+ else
+ raise ArgumentError, "The status #{status.inspect} is invalid"
+ end
+ end
+
private
def ref_path