diff options
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 8dae2d760f5..bddc84f10b5 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -21,6 +21,7 @@ class Environment < ApplicationRecord 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 has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment' has_one :last_deployable, through: :last_deployment, source: 'deployable', source_type: 'CommitStatus' @@ -147,7 +148,7 @@ class Environment < ApplicationRecord Ci::Build.joins(inner_join_stop_actions) .with(cte.to_arel) .where(ci_builds[:commit_id].in(pipeline_ids)) - .where(status: HasStatus::BLOCKED_STATUS) + .where(status: Ci::HasStatus::BLOCKED_STATUS) .preload_project_and_pipeline_project .preload(:user, :metadata, :deployment) end @@ -226,6 +227,21 @@ class Environment < ApplicationRecord available? && stop_action.present? end + def cancel_deployment_jobs! + jobs = active_deployments.with_deployable + jobs.each do |deployment| + # guard against data integrity issues, + # for example https://gitlab.com/gitlab-org/gitlab/-/issues/218659#note_348823660 + next unless deployment.deployable + + Gitlab::OptimisticLocking.retry_lock(deployment.deployable) do |deployable| + deployable.cancel! if deployable&.cancelable? + end + rescue => e + Gitlab::ErrorTracking.track_exception(e, environment_id: id, deployment_id: deployment.id) + end + end + def stop_with_action!(current_user) return unless available? @@ -362,6 +378,11 @@ class Environment < ApplicationRecord def generate_slug self.slug = Gitlab::Slug::Environment.new(name).generate end + + # Overrides ReactiveCaching default to activate limit checking behind a FF + def reactive_cache_limit_enabled? + Feature.enabled?(:reactive_caching_limit_environment, project) + end end Environment.prepend_if_ee('EE::Environment') |