diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /app/models/environment.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 241b454f5ce..36445279b86 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -18,14 +18,13 @@ class Environment < ApplicationRecord belongs_to :cluster_agent, class_name: 'Clusters::Agent', optional: true, inverse_of: :environments use_fast_destroy :all_deployments - nullify_if_blank :external_url, :kubernetes_namespace + nullify_if_blank :external_url, :kubernetes_namespace, :flux_resource_path has_many :all_deployments, class_name: 'Deployment' has_many :deployments, -> { visible } has_many :successful_deployments, -> { success }, class_name: 'Deployment' has_many :active_deployments, -> { active }, class_name: 'Deployment' has_many :prometheus_alerts, inverse_of: :environment - has_many :metrics_dashboard_annotations, class_name: 'Metrics::Dashboard::Annotation', inverse_of: :environment has_many :self_managed_prometheus_alert_events, inverse_of: :environment has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :environment @@ -78,6 +77,10 @@ class Environment < ApplicationRecord message: Gitlab::Regex.kubernetes_namespace_regex_message } + validates :flux_resource_path, + length: { maximum: 255 }, + allow_nil: true + validates :tier, presence: true validate :safe_external_url @@ -331,9 +334,9 @@ class Environment < ApplicationRecord end def cancel_deployment_jobs! - active_deployments.builds.each do |build| - Gitlab::OptimisticLocking.retry_lock(build, name: 'environment_cancel_deployment_jobs') do |build| - build.cancel! if build&.cancelable? + active_deployments.jobs.each do |job| + Gitlab::OptimisticLocking.retry_lock(job, name: 'environment_cancel_deployment_jobs') do |job| + job.cancel! if job&.cancelable? end rescue StandardError => e Gitlab::ErrorTracking.track_exception(e, environment_id: id, deployment_id: deployment.id) @@ -355,8 +358,12 @@ class Environment < ApplicationRecord Gitlab::OptimisticLocking.retry_lock( stop_action, name: 'environment_stop_with_actions' - ) do |build| - actions << build.play(current_user) + ) do |job| + actions << job.play(current_user) + rescue StateMachines::InvalidTransition + # Ci::PlayBuildService rescues an error of StateMachines::InvalidTransition and fall back to retry. However, + # Ci::PlayBridgeService doesn't rescue it, so we're ignoring the error if it's not playable. + # We should fix this inconsistency in https://gitlab.com/gitlab-org/gitlab/-/issues/420855. end end |