From e144369009f3404072f7e0f969f7cded93195a01 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 14 Feb 2020 00:09:07 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/services/ci/stop_environments_service.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/services/ci') diff --git a/app/services/ci/stop_environments_service.rb b/app/services/ci/stop_environments_service.rb index d9a800791f2..14ef744ada1 100644 --- a/app/services/ci/stop_environments_service.rb +++ b/app/services/ci/stop_environments_service.rb @@ -16,6 +16,22 @@ module Ci merge_request.environments.each { |environment| stop(environment) } end + ## + # This method is for stopping multiple environments in a batch style. + # The maximum acceptable count of environments is roughly 5000. Please + # apply acceptable `LIMIT` clause to the `environments` relation. + def self.execute_in_batch(environments) + stop_actions = environments.stop_actions.load + + environments.update_all(auto_stop_at: nil, state: 'stopped') + + stop_actions.each do |stop_action| + stop_action.play(stop_action.user) + rescue => e + Gitlab::ErrorTracking.track_error(e, deployable_id: stop_action.id) + end + end + private def environments -- cgit v1.2.3